Re: comparing two lists

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

```In article <cv3m9k\$cbt\$1 at smc.vnet.net>, Peter Pein <petsie at arcor.de>
wrote:

> You can use Function:
>
> In[1]:=
> (vec = Table[Random[], {2}]) // ColumnForm
> (mat = Table[Random[], {2}, {4}]) // TableForm
> Out[1]=
>         0.360588
>         0.689747
>
> Out[2]=
>         0.948523   0.688799    0.265442    0.953434
>         0.956405   0.416535    0.205109    0.272335
>
> In[3]:=
> Function[{v, m},
>   (Cases[
>     Position[Inner[#1 > #2 &, Transpose[m], v, List], True],
>   {#1, x_} -> x] &) /@ Range[Length[First[m]]]
> ] [vec, mat]
>
> Out[3]=
> {{1, 2}, {1}, {}, {1}}

I also thought of using Inner. However, your solution does not appear to
be correct. Note that #1 > #2 & is just Greater. Here is a slightly
simpler solution using Inner, that gives the correct ouput:

vec = {0.482259,0.314393}

mat= {{0.183706,0.758693,0.462242,0.170041},
{0.457054,0.349658,0.805455,0.127763}}

Position[#, True]& /@ Transpose[Inner[Less, vec, mat, List]]

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: Testing the 'type' of a root returned by Solve
• Next by Date: Re: Computing Complex Series Solution using Mathematica
• Previous by thread: FW: comparing two lists
• Next by thread: [no subject]