Re: How to copy pattern from one expression to another?
- To: mathgroup at smc.vnet.net
- Subject: [mg45267] Re: How to copy pattern from one expression to another?
- From: drbob at bigfoot.com (Bobby R. Treat)
- Date: Wed, 24 Dec 2003 17:42:24 -0500 (EST)
- References: <bsbn05$lri$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
First of all, what you say is straightforward apparently isn't. It
doesn't give the result you think unless f has the Listable property,
as Log does (but most functions don't):
XX = {{x11, x12, x13}, x2,
x3, x4, {x51, x52}, x6,
{x71, x72}, x8};
f[Flatten[XX]]
f[{x11, x12, x13, x2, x3, x4,
x51, x52, x6, x71, x72,
x8}]
Log[Flatten[XX]]
{Log[x11], Log[x12],
Log[x13], Log[x2], Log[x3],
Log[x4], Log[x51],
Log[x52], Log[x6],
Log[x71], Log[x72], Log[x8]}
But this works:
Map[f, XX, {-1}]
{{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
"Nico" <pipponep at hotmail.com> wrote in message news:<bsbn05$lri$1 at smc.vnet.net>...
> 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