I have two input arrays x and y of the same shape. I need to run each of their elements with matching indices through a function, then store the result at those indices in a third array z. What is the most pythonic way to accomplish this? Right now I have four four loops - I'm sure there is an easier way.
x = [[2, 2, 2],
[2, 2, 2],
[2, 2, 2]]
y = [[3, 3, 3],
[3, 3, 3],
[3, 3, 1]]
def elementwise_function(element_1,element_2):
return (element_1 + element_2)
z = [[5, 5, 5],
[5, 5, 5],
[5, 5, 3]]
I am getting confused since my function will only work on individual data pairs. I can't simply pass the x and y arrays to the function.