MathGroup Archive 2005

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

Search the Archive

Re: Applying function to nested lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57921] Re: [mg57883] Applying function to nested lists
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 12 Jun 2005 04:34:53 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

x={{1,2,3},{{4,5,6},7,8},9};

x/.a_?NumericQ:>f[a]

{{f(1),f(2),f(3)},{{f(4),f(5),f(6)},f(7),f(8)},f(9)}

or if f is or can be made Listable

SetAttributes[f, Listable];

f[x]

{{f(1),f(2),f(3)},{{f(4),f(5),f(6)},f(7),f(8)},f(9)}

%==%%%

True


Bob Hanlon

> 
> From: Kerry Kim <kjkim at u.washington.edu>
To: mathgroup at smc.vnet.net
> Date: 2005/06/11 Sat AM 03:35:40 EDT
> Subject: [mg57921] [mg57883]  Applying function to nested lists
> 
> 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
> 
> 


  • Prev by Date: Help with the User Interface in Mathematica 5.1.1
  • 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