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: [mg73592] Re: Map function which adds last two numbers of a list
  • From: "Dana DeLouis" <dana.del at gmail.com>
  • Date: Thu, 22 Feb 2007 04:41:49 -0500 (EST)

Hi.  Here's an option similar to Andrzej's excellent idea in case you have
variables.

z = {{1, 4, 5, 6}, {7, 8, c, d}, {1, 2, 4, 3}}; 

rule = ({w___, x_, y_})?VectorQ -> {w, x + y}; 

z /. rule

{{1, 4, 11}, {7, 8, c + d}, {1, 2, 7}}

HTH
Dana

-- 
Windows XP & Mathematica 5.2
"Christopher Pike" <crpike at ucdavis.edu> wrote in message
news:ergqrb$jg0$1 at smc.vnet.net...
> 
> 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: Find index of maximal element in multi-dimensional array
  • Next by Date: ReplaceList and //.
  • 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