MathGroup Archive 2006

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

Search the Archive

Re: RandomList and pure function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70856] Re: RandomList and pure function
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 30 Oct 2006 05:32:15 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • 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?
> 
> Thanks
> Marc
> _________________________________________________________________
> 
> 
Hi Marc,

Something that the following should fit your needs:

In[1]:=
With[{n = 10}, lst = Table[Random[], {n}, {2}]]

Out[1]=
{{0.42848, 0.543534}, {0.254961, 0.70838},

   {0.612299, 0.775002}, {0.977606, 0.522617},

   {0.774181, 0.38309}, {0.0214249, 0.411784},

   {0.264842, 0.955301}, {0.791362, 0.295489},

   {0.62782, 0.534301}, {0.742154, 0.924198}}

In[2]:=
({First[#1] + 2, Last[#1]} & ) /@ lst

Out[2]=
{{2.42848, 0.543534}, {2.25496, 0.70838},

   {2.6123, 0.775002}, {2.97761, 0.522617},

   {2.77418, 0.38309}, {2.02142, 0.411784},

   {2.26484, 0.955301}, {2.79136, 0.295489},

   {2.62782, 0.534301}, {2.74215, 0.924198}}

Regards,
Jean-Marc


  • Prev by Date: Re: SurfaceColor
  • Next by Date: Re: How to change file names?
  • Previous by thread: Re: RandomList and pure function
  • Next by thread: Simultaneous ODEs