Re: RandomList and pure function
- To: mathgroup at smc.vnet.net
- Subject: [mg70887] Re: RandomList and pure function
- From: albert <awnl at arcor.de>
- Date: Mon, 30 Oct 2006 05:33:33 -0500 (EST)
- References: <ei18or$8n7$1@smc.vnet.net>
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