Lets say I have two arrays:
a = numpy.array([1,2,3,4,5])
b = numpy.array([10,11,12])
I wish to add these arrays together, but I wish to start at index 3 in the first array, to produce:
numpy.array([1,2,3,14,16,12]).
So I'm basically adding an extra 0 to a[3:] to make it the same length as b, and then adding this with b, before appending this result to a[:3].
Can this be done in one step in numpy or do I just implement each of these steps?
def insert(data1, data2, offset):
c = numpy.zeros(len(data2) + offset )
c[:len(data1)] = data1
c[offset:] += data2
return c
c = numpy.zeros(6); c[:5] = a; c[3:] += b
– Haplosis