MathGroup Archive 2007

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

Search the Archive

Re: Map function which adds last two numbers of a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73559] Re: Map function which adds last two numbers of a list
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 21 Feb 2007 06:08:46 -0500 (EST)
  • References: <ergqrb$jg0$1@smc.vnet.net>


Hi Christopher,

write a function that takes a list and replaces its last 2 elements by 

their sum. Then map this function to z:

Append[Drop[#, -2], #[[-1]] + #[[-2]]]& /@ z

Daniel



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

> 




  • Prev by Date: Re: Map function which adds last two numbers of a list
  • Next by Date: Re: How to save the changes to the notebook in help file
  • Previous by thread: Re: Map function which adds last two numbers of a list
  • Next by thread: Re: Map function which adds last two numbers of a list