MathGroup Archive 2005

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

Search the Archive

Re: comparing two lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54637] Re: comparing two lists
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Fri, 25 Feb 2005 01:18:36 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <200502161936.OAA19139@smc.vnet.net> <cv3m5r$cb7$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <cv3m5r$cb7$1 at smc.vnet.net>,
 Andrzej Kozlowski <akoz at mimuw.edu.pl> wrote:

> I would say the simplest way to solve your problem is:
> 
> MyFunction1[mat_?MatrixQ, vec_?VectorQ] :=Position[mat - vec, _?(# > 0  
> &)]
> 
> For example with your data this gives:
> 
> In[2]:=
> mat={{0.183706,0.758693,0.462242,0.170041},{0.457054,0.349658,0.805455,0 
> .\
> 127763}};
> 
> In[3]:=
> vec={0.482259,0.314393};
> 
> In[4]:=
> MyFunction1[mat,vec]
> 
> Out[4]=
> {{1,2},{2,1},{2,2},{2,3}}
> 
> This tells you exactly the positions you wanted but not in the form you  
> asked for. Getting the output into that form will be the most  
> complicated part of the problem, so if you really do not need it I  
> would rather settle for the above. But of course there are lots of ways  
> to get exactly the answer you asked for.  You could try to bring the  
> answer above into the form you want or you could use something like:
> 
> MyFunction2[mat_?MatrixQ, vec_?VectorQ] :=  
> Map[Flatten[Position[mat[[#]] -
> vec[[#]], _?(# > 0 &)]] &, Range[Length[vec]]]

A simpler solution, very close to the original proposal
(Position[#1,_?(#>#2&)]&@@{mat,vec}) is

  Position[#, _?(# > 0 &)] & /@ (mat - vec)

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 6488 2734
School of Physics, M013                         Fax: +61 8 6488 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: finding roots of 1 + 6*x - 8*x^3
  • Next by Date: Re: finding roots of 1 + 6*x - 8*x^3
  • Previous by thread: Re: comparing two lists
  • Next by thread: Re: comparing two lists