Re: proper way to manipulate lists?
- To: mathgroup at smc.vnet.net
- Subject: [mg40185] Re: proper way to manipulate lists?
- From: burd at gmx.net (Oleg)
- Date: Tue, 25 Mar 2003 14:47:23 -0500 (EST)
- References: <b5p158$7sk$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
One of the possible solutions:
array = Table[{"x" <> ToString[i], "y" <> ToString[i]}, {i, 10^4}] //
ToExpression;
In[7]:=
ByteCount[array]
Out[7]=
280024
In[8]:=
array[[100]]
Out[8]=
{x100, y100}
In[11]:=
array2 = {a #[[1]], b #[[2]]} & /@ array; // Timing
Out[11]=
{0.094 Second, Null}
In[10]:=
array2[[100]]
Out[10]=
{a x100, b y100}
Nathan Moore <nmoore at physics.umn.edu> wrote in message news:<b5p158$7sk$1 at smc.vnet.net>...
> I'm sure this is a one-liner, but it has stumped me for years. Suppose
> I'm working with a 2-d array of data,
> data = {{x1,y1},{x2,y2}...{xN,yN}};
> and I want to transform the data according to,
> data2 = {{x1*a,y1*b},{x2*a,y2*b}...{xN*a,yN*b}};
> The only way I know to do this is to move the data to excel,
> performing the transform and then move the data back to Mathematica. This
> is crazy - there must be a better way - is there? Please tell me there
> is!
>
> regards,
>
> Nathan Moore, University of Minnesota Physics Department