Re: Newbie question

• To: mathgroup at smc.vnet.net
• Subject: [mg25305] Re: Newbie question
• From: Laurent CHUSSEAU <chusseau at univ-montp2.fr>
• Date: Tue, 19 Sep 2000 03:45:30 -0400 (EDT)
• References: <8q3dvc\$kbb@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```dans l'article 8q3dvc\$kbb at smc.vnet.net, Jose M Lasso à jml at accessinter.net a
écrit le 17/09/2000 23:44 :

> Hi Mathgroup,
>
> I have some numerical data: data:={{x,y},{x1,y1},{x2,y2}....{xn,yn}},
> I want to transform the data like this:
> data1:={{x,1/y},{x1,1/y1},{x2,1/y2}....{xn,1/yn}}, how can I do this
> transformation? Thanx in advance. Regards
>
> Jose M Lasso
>

Let me extend my previous answer by CPU time considerations. The solution I
proposed works well but you can also do that more efficeintly with the
function Transpose.

Here is my previous solution

In[2]:=
Timing[aa=Table[{i,i},{i,500000}];]

Out[2]=
{3.36667 Second,Null}

In[19]:=
Timing[{#\[LeftDoubleBracket]1\[RightDoubleBracket],
1/#\[LeftDoubleBracket]2\[RightDoubleBracket]}&/@aa;]

Out[19]=
{15.3833 Second,Null}

Here is another by defining a pure function process that uses Transpose

In[15]:=
process=Transpose[{Transpose[#]\[LeftDoubleBracket]1\[RightDoubleBracket],
1/Transpose[#]\[LeftDoubleBracket]2\[RightDoubleBracket]}]&

Out[15]=
\!\(Transpose[{\(Transpose[#1]\)\[LeftDoubleBracket]1\[RightDoubleBracket],
1\/\(Transpose[#1]\)\[LeftDoubleBracket]2\[RightDoubleBracket]}]&\)

In[17]:=
Timing[process[aa];]

Out[17]=
{8.21667 Second,Null}

... with large data you can gain a factor of 2 in time.

--
Laurent CHUSSEAU, CR CNRS, CEM2 UMR5507, Universite de Montpellier II

```

• Prev by Date: Re: Fixing options to Cell expressions
• Next by Date: Re: Random spherical troubles
• Previous by thread: RE: Newbie question
• Next by thread: Re: Newbie question