MathGroup Archive 2006

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

Search the Archive

Re: Summing elements within a List or Array


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