Re: Applying function to nested lists

• To: mathgroup at smc.vnet.net
• Subject: [mg57959] Re: [mg57883] Applying function to nested lists
• From: János <janos.lobb at yale.edu>
• Date: Tue, 14 Jun 2005 05:10:23 -0400 (EDT)
• References: <200506110735.DAA16848@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On Jun 11, 2005, at 3:35 AM, Kerry Kim wrote:

> 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
>

In[1]:=
lst = {{1, 2, 3}, {{4, 5, 6},
7, 8}, 9}
Out[1]=
{{1, 2, 3}, {{4, 5, 6}, 7,
8}, 9}

In[2]:=
MapAt[f, lst, Position[lst,
_Integer]]
Out[2]=
{{f[1], f[2], f[3]},
{{f[4], f[5], f[6]}, f[7],
f[8]}, f[9]}

János

--------------------------------------------
f @@ # & /@ ===  f @@@

```

• Prev by Date: Re: Q: Thread behaviour
• Next by Date: Re: Q: Thread behaviour
• Previous by thread: Re: Applying function to nested lists
• Next by thread: Reducing memory for big data sets