We have some arrays of the same shape and want to merge them.
By "merge", I mean output a new array with the sum of each i,j in each of the arrays in each position.
import numpy as np
first = np.array([[1,1],[1,1]])
second = np.array([[2,2],[2,2]])
third = np.array([[3,3],[3,3]])
The result should be:
[[6,6],
[6,6]]
Here's my code...but is there a cleaner way? I can't seem to find a built-in method:
def merge_arrays(arrays):
output = arrays[0]
for a in arrays[1:]:
for i,row in enumerate(a):
for j,col in enumerate(row):
output[i,j] += a[i,j]
return output
merge_arrays([first, second, third])