Re: Applying function to nested lists

• To: mathgroup at smc.vnet.net
• Subject: [mg57908] Re: Applying function to nested lists
• From: "Carl K. Woll" <carlw at u.washington.edu>
• Date: Sun, 12 Jun 2005 04:34:33 -0400 (EDT)
• Organization: University of Washington
• References: <d8e525\$gnl\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```"Kerry Kim" <kjkim at u.washington.edu> wrote in message
news:d8e525\$gnl\$1 at smc.vnet.net...
> Hello,
>
> I'm trying to get Mathematica to do the following:
>
> Suppose
> x = {{1,2,3},{{4,5,6},7,8},9}
> f = some function
>
> How can I get f applied to each element of x but with the list structure
> intact?  I.e. I want something that generates:
>
> {{f[1],f[2],f[3]},{{f[4],f[5],f[6]},f[7],f[8]},f[9]}
>
> Thank you!
> -Kerry Kim
>

Use Map with a level specification:

In[3]:=
Map[f, x, {-1}]
Out[3]=
{{f[1], f[2], f[3]}, {{f[4], f[5], f[6]}, f[7], f[8]}, f[9]}

Carl Woll
Wolfram Research

```

• Prev by Date: Re: Applying function to nested lists
• Next by Date: Re: "expanding a list"
• Previous by thread: Re: Applying function to nested lists
• Next by thread: Re: Applying function to nested lists