MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Comparing Corresponding Columns of Two Matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97555] Re: Comparing Corresponding Columns of Two Matrices
  • From: Raffy <raffy at mac.com>
  • Date: Sun, 15 Mar 2009 05:27:42 -0500 (EST)
  • References: <gpg1gu$cl7$1@smc.vnet.net>

On Mar 14, 3:39 am, Gregory Lypny <gregory.ly... at videotron.ca> wrote:
> Hello everyone,
>
> I'm trying to develop a modest skill in mapping functions and I've  
> been working on this problem.
>
> Suppose I have two 100 x 4 matrices, X and Y, and I want to see  
> whether each value in a column of X is bigger than each value in the  
> corresponding column of Y.  In other words, compare column 1 of X with =
 
> column 1 of Y, column 2 of X with column 2 of Y, and so on.
>
> It's easy to generate a 100 x 4 table of Booleans using Table as
>
>         Table[Boole[X[[i ,  j]] > Y[[i, j]]], {i, 100}, {j, 4}]
>
> But what about without Table?  I am able to do it for the comparison =
 
> of any one column as
>
>         Boole[#[[1]] > #[[2]]] & /@ Transpose[{X[[All, ]], Y[[All=
, 1]]}]
>
> but I'm not sure how to extend this to other columns.  Any tip would =
 
> be much appreciated.
>
> Regards,
>
>         Gregory

X = RandomReal[{0, 1}, {100, 4}];
Y = RandomReal[{0, 1}, {100, 4}];

r1 = Boole@MapThread[Greater, {X, Y}, ArrayDepth[X]];

Or, even better:

r2 = Clip[X - Y, {0, 0}, {0, 1}];


  • Prev by Date: Re: Hash function
  • Next by Date: Re: Re: Two Notebooks Open at the Same Time
  • Previous by thread: Re: Comparing Corresponding Columns of Two Matrices
  • Next by thread: Re: Comparing Corresponding Columns of Two Matrices