Re: how to sum lists of unequal length?
- To: mathgroup at smc.vnet.net
- Subject: [mg70443] Re: [mg70352] how to sum lists of unequal length?
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Mon, 16 Oct 2006 02:35:58 -0400 (EDT)
- Reply-to: hanlonr at cox.net
sumLists[a_?VectorQ, b_?VectorQ] := Module[{len = Max[Length /@ {a, b}]}, PadRight[a, len] + PadRight[b, len]]; sumLists[{a1, a2, a3}, {b1, b2, b3, b4, b5}] {a1+b1,a2+b2,a3+b3,b4,b5} Bob Hanlon ---- Arkadiusz.Majka at gmail.com wrote: > Hi all, > > 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. > > Please, help > > Arek > -- Bob Hanlon hanlonr at cox.net