Re: How to copy pattern from one expression to another?
- To: mathgroup at smc.vnet.net
- Subject: [mg45273] Re: How to copy pattern from one expression to another?
- From: drbob at bigfoot.com (Bobby R. Treat)
- Date: Sat, 27 Dec 2003 05:00:13 -0500 (EST)
- References: <200312240935.EAA22289@smc.vnet.net> <bsd5bg$rae$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Or just... XX = {{x11, x12, x13}, x2, x3, x4, {x51, x52}, x6, {x71, x72}, x8}; SetAttributes[f, Listable] f[XX] {{f[x11], f[x12], f[x13]}, f[x2], f[x3], f[x4], {f[x51], f[x52]}, f[x6], {f[x71], f[x72]}, f[x8]} Bobby Tomas Garza <tgarza01 at prodigy.net.mx> wrote in message news:<bsd5bg$rae$1 at smc.vnet.net>... > One possibility is to set the attribute Listable to your function f (I'd > rather use lower case): > > In[1]:= > XX = {{x11, x12, x13}, x2, x3, x4, {x51, x52}, x6, > {x71, x72}, x8}; > > In[2]:= > f /@ XX > Out[15]= > {f[{x11, x12, x13}], f[x2], f[x3], f[x4], > f[{x51, x52}], f[x6], f[{x71, x72}], f[x8]} > > Now, if you set > > In[3]:= > SetAttributes[f, Listable] > In[4]:= > f /@ XX > Out[4]= > {{f[x11], f[x12], f[x13]}, f[x2], f[x3], f[x4], > {f[x51], f[x52]}, f[x6], {f[x71], f[x72]}, f[x8]} > > Tomas Garza > Mexico City > ----- Original Message ----- > From: "Nico" <pipponep at hotmail.com> To: mathgroup at smc.vnet.net > Subject: [mg45273] How to copy pattern from one expression to another? > > > > Hi everyone and Merry Christmas! > > Here's my issue: I have a vector such as > > XX={{x11,x12,x13},x2,x3,x4,{x51,x52},x6,{x71,x72},x8} and I would like to > > apply the same function F[x_] to each single element in it. This is indeed > > pretty straightforward even to a very basic user like I am: I can first > > Flatten[XX] and then apply F[Flatten[XX]]. What I get is then > > YY={F[x11],F[x12],F[x12],...}. > > The question is: how can I then have YY with the same pattern of XX, that > is > > YY_hat={{F[x11],F[x12],F[x12]},F[x2],....,{F[x51],F[x52]},F[x6],{F..,F}}? > > I have tried but I'm afraid I cannot focus exactly the way I should > approach > > the problem. > > Any suggestion anyone? I'd really appreciate it... > > > > Kind regards and many thanks! > > The Net > > > >
- References:
- How to copy pattern from one expression to another?
- From: "Nico" <pipponep@hotmail.com>
- How to copy pattern from one expression to another?