Re: comparing two lists
- To: mathgroup at smc.vnet.net
- Subject: [mg54325] Re: [mg54284] comparing two lists
- From: DrBob <drbob at bigfoot.com>
- Date: Thu, 17 Feb 2005 10:30:44 -0500 (EST)
- References: <200502161936.OAA19139@smc.vnet.net>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
How's this?
vec = {0.482259, 0.314393};
mat = {{0.183706, 0.758693,
0.462242, 0.170041}, {0.457054, 0.349658, 0.805455, 0.127763}};
g = Flatten /@ Function[{x, y}, Position[x, _?(# > y &)]] @@@ Transpose@# &;
g@{mat, vec}
{{2}, {1, 2, 3}}
Bobby
On Wed, 16 Feb 2005 14:36:02 -0500 (EST), Curt Fischer <tentrillion at gmail.NOSPAM.com> wrote:
> Dear Group:
>
> I want to write a function that accepts a n-vector and an n x m matrix.
> It should return a list of positions in the matrix where mat[[i,j]] >
> vec[[i]]. For example,
>
> In[287]:=
> vec=Table[Random[],{2}]
>
> Out[287]=
> {0.482259,0.314393}
>
> In[288]:=
> mat=Table[Table[Random[],{4}],{2}]
>
> Out[288]=
> {{0.183706,0.758693,0.462242,0.170041},{0.457054,0.349658,0.805455,0.127763}}
>
> I would like myFunc[] to return {{2},{1,2,3}}.
>
> How could I write this as a pure function? Ideally I would like to be
> able to Map or Apply my function to the list {mat, vec} and get my result.
>
> Something like
>
> Position[#1,_?(#>#2&)]&@@{mat,vec}
>
> is doomed to fail because the PatternTest required in Position[] messes
> up the slotting of the other arguments.
>
> Ideas? How do you nest pure functions?
>
--
DrBob at bigfoot.com
www.eclecticdreams.net
- References:
- comparing two lists
- From: Curt Fischer <tentrillion@gmail.NOSPAM.com>
- comparing two lists