>>> a = np.array([0, 0])
>>> a[[0, 0, 1, 1]] + [1, 2, 3, 4]
array([1, 2, 3, 4])
>>> a[[0, 0, 1, 1]] += [1, 2, 3, 4]
>>> a
array([2, 4])
I understand that a[[0, 0, 1, 1]] returns a view of a, whose first two elements point to a[0] and last two elements point to a[1]. Now what if I want to get a = [3, 7]? Which is to say, what is the easiest way to accomplish the following?
a = [0, 0]
indices = [0, 0, 1, 1]
values_to_add = [1, 2, 3, 4]
for i in indices:
a[i] += values_to_add[i]