Re: Adding the elements of a list sequentially
- To: mathgroup at smc.vnet.net
- Subject: [mg109339] Re: Adding the elements of a list sequentially
- From: mokambo <alexandrepassosalmeida at gmail.com>
- Date: Thu, 22 Apr 2010 06:43:06 -0400 (EDT)
- References: <hqotti$9ch$1@smc.vnet.net>
On Apr 22, 8:29 am, eba... at illinois.edu wrote: > I am looking for an efficient way to add the elements of a list > sequentially onto another list > > For example, generate list c, given lists a and b: > > a = {1,2,3,4,5,6,7,8,9,10} > b = {1,2} > > c = {2,4,4,5,6,7,8,9,10,11} > > another example: > > a = {1,1,1,1,1} > b = {1,2,3} > > c = {2,3,4,2,3} > > It seems like there must be a built in function to do this, but > have been unable to find it. > > Thanks a 10^6 > Jason Ebaugh One way to do it is: c = a + PadRight[b, Length[a], b] Alex