MathGroup Archive 1998

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

Search the Archive

RE: Plotting Data




In the lines below I compare the timing of solutions from Alan Hayes,
Sean  Ross, and
a few I came up with.  They all have the same result when you get rid of
"//Timing//First".

My favorite is:     data/.{x_,y_}->{x,f[y]} That's because it's very
readable, easy to write, and the timing is not too  sloggish.


In Dave Wagner's excellent book "Power Programming with Mathematica: the
Kernal",  he tells us it's inefficient to tear apart a list and put it
back  together with a similar structure.  That explains why the worst
performer  is:
Table[{data[[n,1]],f[data[[n,2]]]},{n,1,Length[data]}]

Ted Ersek

 ----------
|From: "seanross"@worldnet.att.net@PMDF@PAXMB1 To:
mathgroup@smc.vnet.net
|To: ersek ted; "mathgroup"@smc.vnet.net@PMDF@PAXMB1 |Subject: [mg10777] [mg10720]
Re: [mg10716] Plotting Data |Date: Monday, February 02, 1998 5:55AM |
|<<File Attachment: 00000000.TXT>>
|Larry C Linik wrote:
|>
|> I'm plotting data from a table (x,y] and I want to apply a function
to |> the y  values to plot (x,f[y]].  How can I do this? |>
|> Thanks,
|> Larry
|
|
|Assuming a table of data called data, then generate a new table using |
|Table[{data[[n,1]],f[data[[n,2]]},{n,start, end}] -- |Remove the
_nospam_ in the return address to respond. |

In[1]:=
data=Table[{Random[],Random[]},{10^5}];


In[2]:=
Table[{data[[n,1]],f[data[[n,2]]]},{n,1,Length[data]}] //Timing//First

Out[2]=
26.31 Second


In[3]:=
Map[MapAt[foo,#,2]&,data]//Timing//First

Out[3]=
14.88 Second


In[4]:=
Apply[{#,f[#2]}&, data,1]//Timing//First

Out[4]=
11.42 Second


In[5]:=
data/.{x_,y_}->{x,f[y]}//Timing//First

Out[5]=
9.39 Second


In[6]:=
Transpose[MapAt[foo/@#&,Transpose[data],2]]//Timing//First

Out[6]=
6.04 Second


In[7]:=
Thread[MapAt[foo/@#&,Thread[data],2]]//Timing//First

Out[7]=
5.94 Second


Question:
Thread is a generalization of Transpose.  Right? Is Thread always faster
than Transpose?  If it is why should we ever use  Transpose?




  • Prev by Date: Mathematica Palettes
  • Next by Date: 3D Graphics in Spherical Coordinates
  • Prev by thread: Re: Plotting Data
  • Next by thread: Re: MathLink connection from Mac to UNIX