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

• To: mathgroup at smc.vnet.net
• Subject: [mg5457] Re: Q:Nicer than: Function[x,MapAt[Im,x,2]]/@data
• From: Clemens Frey <Clemens.Frey at uni-bayreuth.de>
• Date: Sat, 7 Dec 1996 00:26:35 -0500
• Organization: uni-bayreuth.de
• Sender: owner-wri-mathgroup at wolfram.com

```rommel at bc.edu wrote:
>
> I want to ListPlot the imaginary part of data:
>
> data={{x0,z0},{x1,z1},{x2,z2}}
>
> The x? are real, the z? complex.
>
> My simple but ugly solution was
>
> Transpose[{Transpose[data][[1]],Im[Transpose[data][[2]]]}]
>
> after reading a little I came to the shorter
>
> Function[x,MapAt[Im,x,2]]/@data
>
> Is there a nicer way to do it?

Hi,

pattern matching can do a good job here.
Just having defined

data = {{1.,I},{2,1+2*I}};

try the following:

data /. {_Real,y_} -> Im[y] /. {_Integer,y_} -> Im[y]

to get a list of imaginary parts of the second components
of the pairs in the list.
If you are sure that all first components are really Real
(other than in the example above!), then you can drop the
"/. {_Integer,y_} -> Im[y]" - thing.
I used _Real instead of _ alone to avoid problems with
lists of two pairs, on which {_,y_} would also match :-{.

Hope this is what you needed

Clemens
(-: Clemens.Frey at uni-bayreuth.de :-)

```

• Prev by Date: Re: select a range of elements from a nested list
• Next by Date: Re: Q:Nicer than: Function[x,MapAt[Im,x,2]]/@data
• Previous by thread: Re: Q:Nicer than: Function[x,MapAt[Im,x,2]]/@data
• Next by thread: Re: Q:Nicer than: Function[x,MapAt[Im,x,2]]/@data