Re: how to sum lists of unequal length?
- To: mathgroup at smc.vnet.net
- Subject: [mg70405] Re: how to sum lists of unequal length?
- From: email at email.com
- Date: Sun, 15 Oct 2006 00:20:14 -0400 (EDT)
- References: <egq2th$84h$1@smc.vnet.net>
Probably one of the 20 proposals that will come out, but here is one... In[4]:= sumUnequalLengthLists[a_List, b_List] := Module[{length = Min[Length /@ {a, b}]}, Flatten[{Plus[Sequence @@ (Take[#1, length] & ) /@ {a, b}], (Drop[#1, length] & ) /@ {a, b}}]]; GL On Sat, 14 Oct 2006 07:17:05 +0000 (UTC), 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