Mathematica 9 is now available
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: how to sum lists of unequal length?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70386] Re: how to sum lists of unequal length?
  • From: Bill Rowe <readnewsciv at sbcglobal.net>
  • Date: Sun, 15 Oct 2006 00:18:51 -0400 (EDT)

On 10/14/06 at 3:06 AM, Arkadiusz.Majka at gmail.com wrote:

>I have lists of unknown and unequal lengths. I want to sum them, e.g

>{a1,a2,a3}+{b1,b2,b3,b4,b5} and obtain result
>{a1+b1,a2+b2,a3+b3,b4,b5}. Simply filling by zeros of the shorter
>list is impossible because I have no idea how many zeros I have to
>pad.

Have Mathematica figure out how many zeros to pad, i.e.,

In[11]:=
lists={{a1,a2,a3},{b1,b2,b3,b4,b5}};

In[12]:=
m=Max[Length/@lists]

Out[12]=
5

In[13]:=
Plus@@@Transpose[PadRight[#,m]&/@%2]

Out[13]=
{a1+b1,a2+b2,a3+b3,b4,b5}
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: how to sum lists of unequal length?
  • Next by Date: Re: how to sum lists of unequal length?
  • Previous by thread: Re: how to sum lists of unequal length?
  • Next by thread: Re: how to sum lists of unequal length?