Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg73576] Re: [mg73530] Map function which adds last two numbers of a list
  • From: János <janos.lobb at yale.edu>
  • Date: Thu, 22 Feb 2007 04:33:05 -0500 (EST)
  • References: <200702210646.BAA18238@smc.vnet.net>

On Feb 21, 2007, at 1:46 AM, 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


Here is a newbie suggestion:

In[24]:=
fz[x_] := Join[Most[Most[x]],
    {Total[Complement[x,
       Most[Most[x]]]]}]

In[26]:=
(fz[#1] & ) /@ z
Out[26]=
{{1, 4, 11}, {7, 8, 10},
   {1, 2, 7}}

J=E1nos


------------------------------------------
"The shortest route between two points is the middleman"  Ayn Rand



  • Prev by Date: Re: Showing that ArcSinh[2]/ArcCsch[2] is 3?
  • Next by Date: RE: Re: Quick integral.
  • 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