Re: Map function which adds last two numbers of a list
- To: mathgroup at smc.vnet.net
- Subject: [mg73560] Re: Map function which adds last two numbers of a list
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 21 Feb 2007 06:09:18 -0500 (EST)
- Organization: Uni Leipzig
- References: <ergqrb$jg0$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi,
Map[Append[Drop[#, -2], Plus @@ Take[#, -2]] &, z]
Regards
Jens
Christopher Pike wrote:
> Hi,
> Consider this:
>
> z = {{1,4,5,6},{7,8,9,1},{1,2,4,3}}
>
> I'd like to Map a function onto z which would replace the last two items
> with their sum:
>
> {{1,4,11},{7,8,10},{1,2,7}}
>
> I could easily use the Table command to construct this new table, but it
> would be nicer if I new how to Map some function on z that would produce
> the same result.
>
> Any suggestions.
>
> Thanks, Chris Pike
>