Re: Map vs. Table
- To: mathgroup at smc.vnet.net
- Subject: [mg75402] Re: Map vs. Table
- From: Bill Rowe <readnewsciv at sbcglobal.net>
- Date: Sat, 28 Apr 2007 05:59:37 -0400 (EDT)
On 4/27/07 at 5:25 AM, replicatorzed at gmail.com (zac) wrote: >consider a set of data (y values): >data = Table[i*j, {i, 5}, {j, 10}] The same data can be generated more quickly with Outer. That is: In[15]:= Outer[Times,Range@5,Range@10]==Table[i*j,{i,5},{j,10}] Out[15]= True and In[16]:= Timing[Do[Table[i*j,{i,5},{j,10}],{10000}];] Out[16]= {0.947914 Second,Null} while In[17]:= Timing[Do[Outer[Times,Range@5,Range@10],{10000}];] Out[17]= {0.451616 Second,Null} >I want to label each Integer with an x value: >label := Table[{i, #} & /@ data[[i]], {i, Length[data]}] =46or this, MapIndexed is works nicely, i.e., In[18]:= Join@@MapIndexed[Outer[List,#2,#1]&,Outer[Times,Range@5,Range@ 10]]==Table[{i,#}&/@data[[i]],{i,Length[data]}] Out[18]= True and In[19]:= Timing[Do[Join@@MapIndexed[Outer[List,#2,#1]&,data],{10000}];] Out[19]= {0.557445 Second,Null} -- To reply via email subtract one hundred and four