       Re: Questions on Apply function

• To: mathgroup at smc.vnet.net
• Subject: [mg62912] Re: [mg62866] Questions on Apply function
• From: Sseziwa Mukasa <mukasa at jeol.com>
• Date: Thu, 8 Dec 2005 00:05:31 -0500 (EST)
• References: <200512070411.XAA23793@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```On Dec 6, 2005, at 11:11 PM, PengYu.UT at gmail.com wrote:

> Please look at the following code. I'm wondering the output 1 doesn't
> give me the right answer. 6435-4545 should be 1890. Is there anything
> wrong with input 1? It seems that it is correct, because input 3 works
> well.
>
> Thanks,
> Peng
>
> In:=
> Apply[(#+{-6750,6435})&,{{6945,-4545},{6945, -4545}},{1}]
>
> Out=
> {{195,13380},{195, 13380}}
>
> In:=
> {-6750,6435}+{6945,-4545}
>
> Out=
> {195,1890}
>
> In:=
> Apply[(#+{a,b})&,{{a1,b1},{a2,b2},{a3,b3}},{1}]
>
> Out=
> {{a+a1,a1+b},{a+a2,a2+b},{a+a3,a3+b}}

This doesn't appear to be what you want, what you are looking for is

{{a+a1,b1+b},{a+a2,b2+b},{a+a3,b3+b}}

You can use Map instead of Apply to get this result

In:=
Map[(#+{a,b})&,{{a1,b1},{a2,b2},{a3,b3}},{1}]

Out=
{{a+a1,b+b1},{a+a2,b+b2},{a+a3,b+b3}}

Regards,

Ssezi

```

• Prev by Date: Re: Questions on Apply function
• Next by Date: Re: Questions on Apply function
• Previous by thread: Questions on Apply function
• Next by thread: Re: Questions on Apply function