[Date Index]
[Thread Index]
[Author Index]
Re: Re: Apply function to parts of a list
Stern wrote:
><I sent this reply to guerom00 directly but am resending it to group so it
>gets archived for posterity>
>
>On Thu, Mar 6, 2008 at 8:43 AM, Stern <nycstern at gmail.com> wrote:
>
>
>
>>There are probably a lot of ways to do this. The most natural for me is to
>>use nested Transpose commands; this has the advantage of avoiding anonymous
>>functions, so it's clearer if nested in the middle of other commands that
>>use anonymous functions.
>>my way:
>>
>>Transpose[{2*Transpose[data][[1]], Transpose[data][[2]]}]
>>
>>
Even faster is:
Transpose[{2,1} Transpose[data]]
A slower alternative is to use ScalingTransform (new in 6):
ScalingTransform[{2,1}][data]
There is also AffineTransform, RescalingTransform, TranslationTransform
and RotationTransform, providing useful tools for tranforming vectors.
Carl Woll
Wolfram Research
>>
>>This may not be memory- or compute-efficient, as it requires repeating the
>>Transpose[data] command, so for large datasets you may prefer
>>
>>
>>Module[{transp}, transp = Transpose[data];
>> Transpose[{2*transp[[1]], transp[[2]]}]];
>>
>>
>>Either of these is quicker than where you started --
>>
>>
>>In[19]:= Timing[MapAt[2*# &, data, Table[{i, 1}, {i, 1, Length[data]}]];]
>>Out[19]= {0.004409, Null}
>>
>>
>>In[20]:= Timing[Transpose[{2*Transpose[data][[1]],
>>Transpose[data][[2]]}];]
>>Out[20]= {0.000672, Null}
>>
>>
>>In[21]:= Timing[Module[{transp}, transp = Transpose[data];
>> Transpose[{2*transp[[1]], transp[[2]]}]];]
>>Out[21]= {0.000698, Null}
>>
>>
>>Cheers,
>>
>>
>>Michael
>>
>>
>>
>>On Thu, Mar 6, 2008 at 2:59 AM, guerom00 <guerom00 at gmail.com> wrote:
>>
>>
>>
>>>Hi all,
>>>
>>>Very often, I find myself having datas to plot of this form :
>>>
>>>data={{x1,y1},{x2,y2},{x3,y3}...{xn,yn}}
>>>
>>>So, very conventional : a list of abscissa and ordinate. Now, let's say
>>>I want to multiply by 2 all my ascissa. Right now, I write :
>>>
>>>MapAt[2*#&,data,Table[{i,1},{i,1,Length[data]}]]
>>>
>>>It's OK but I isn't there another way to achieve this as I find this
>>>rather "involved" for such a simple thing ?
>>>
>>>Thanks in advance.
>>>
>>>
>>>
>>>
Prev by Date:
**Re: Re: Re: Version 6.0.2**
Next by Date:
**Re: Re: Mathematica 6 obtains imaginary eigenvalues for a Hermitian**
Previous by thread:
**Re: Apply function to parts of a list**
Next by thread:
**Re: Apply function to parts of a list**
| |