MathGroup Archive 1996

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

Search the Archive

Q:Nicer than: Function[x,MapAt[Im,x,2]]/@data

  • To: mathgroup at
  • Subject: [mg5466] [mg5389] Q:Nicer than: Function[x,MapAt[Im,x,2]]/@data
  • From: Allan Hayes <hay at haystack>
  • Date: Sat, 7 Dec 1996 00:26:47 -0500
  • Sender: owner-wri-mathgroup at

rommel at
[mg5389] Q:Nicer than:  Function[x,MapAt[Im,x,2]]/@data
I want to ListPlot the imaginary part of data:


The x? are real, the z? complex.

My simple but ugly solution was


after reading a little I came to the shorter


Is there a nicer way to do it?

Some Experiments:

lst = Table[{Random[],Random[]+I Random[]},{2000}];

Function[x,MapAt[Im,x,2]]/@lst;//Timing        (*your "shorter" one*)
{1.25 Second, Null}

MapAt[Im,#,2]&/@lst;//Timing                     (*faster function*)
{0.7 Second, Null}

Apply[{#,Im[#2]}&,lst,1];//Timing                (*use Apply*)
{0.466667 Second, Null}

lst/.Complex[x_,y_]:>y;//Timing			 (*pattern matching*)
{0.483333 Second, Null}

lst/.{a_,Complex[x_,y_]}:>{a,y};//Timing         (*help matching*)
{0.383333 Second, Null}

MapAt[Im,Transpose[lst],{2}]//Transpose;//Timing  (*your "ugly" one*)
{0.3 Second, Null}

MapAt[Im,Thread[lst],{2}]//Thread;//Timing      (*Thread faster  
than Transpose*)
{0.25 Second, Null}

Allan Hayes
hay at

  • Prev by Date: Thanks for Rearrangement & Format
  • Next by Date: Re: bodeplot
  • Previous by thread: Q:Nicer than: Function[x,MapAt[Im,x,2]]/@data
  • Next by thread: Re: Q:Nicer than: Function[x,MapAt[Im,x,2]]/@data