I have a ndarray of size (M, N, 3). It holds M x N points, each of which is identified by its x, y, and z coordinates. I also have a function 'foo'. 'foo' takes in a point as a ndarray of size (, 3). Is there a faster way to call 'foo' on each of the M x N points in my array than to use two nested for loops?
So far, this is what I have tried. My array is the variable 'sample_array'.
num_rows = sample_array.shape[0]
num_columns = sample_array.shape[1]
solution = np.zeros((num_rows, num_columns))
for row in range(num_rows):
for column in range(num_columns):
point = sample_array[row, column]
solution[row, column] = foo(point)
I found this answer, which describes using these two solutions:
np.vectorize(foo)
np.array(map(foo, sample_array))
However, I am not sure how to specify that I don't want the function mapped to every one of the M x N x 3 floats. Instead, I would like it to map the function to be called on each of the M x N (, 3) ndarrays.
Thank you!