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

MathGroup Archive 2006

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

Search the Archive

Re: Summing elements within a List or Array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69560] Re: Summing elements within a List or Array
  • From: "dkr" <dkrjeg at adelphia.net>
  • Date: Fri, 15 Sep 2006 06:46:13 -0400 (EDT)
  • References: <eebfs6$57q$1@smc.vnet.net>

John,

In[12]:=
alist={{0},{{1.2},0},{{2.3},{1.2},0}};

You can exploit the special structure of your list (namely that each
sublist consists of a list together with all the elements of the
previous sublist) by using:

In[13]:=
FoldList[Plus,0,alist[[All,1]]//Flatten]//Rest
Out[13]=
{0,1.2,3.5}

In general, where this special structure may not be present (i.e., the
sublists contain arbitrary elements), you can:
In[14]:=
Plus@@@alist//Flatten
Out[14]=
{0,1.2,3.5}

dkr


  • Prev by Date: How to combine 3 grayscale images into one RGB color image ?
  • Next by Date: Re: Color names and the 10 elementary colors?
  • Previous by thread: Re: Summing elements within a List or Array
  • Next by thread: Re: Summing elements within a List or Array