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