MathGroup Archive 2006

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

Search the Archive

Re: RandomList and pure function


Marc VIAL wrote:

> 
> Hi,
> 
> Sorry for this naive question, but I try to apply a pure function of 2
> arguments to a list of n rows with 2 clm using the mapping function:
> 
> n=100;lis=RandomReal[{0,1},{n,2}];
> (#1+2 #2)&/@lis
> 
> however it only captures the first term in the list and leave #2
> unassigned.
> 
> Any advice?

Note that using your construct the pure function does not see two arguments
but one argument which happens to be a list of two numbers. So this should
work:

(#[[1]]+2*#[[2]])& /@ lis

If you want to apply a function of two arguments, you will in this case need
to use Apply, not Map. The following does this:

(#1 + 2 #2) & @@@ lis

and is a shorthand for:

Apply[(#1 + 2 #2) &, lis, {1}]

hth,

albert


  • Prev by Date: Counting Symbols
  • Next by Date: Re: RandomList and pure function
  • Previous by thread: Re: RandomList and pure function
  • Next by thread: Re: RandomList and pure function