How to apply a function to the subarrays of a (m,n,n) numpy array without using a for-loop

53 Views Asked by At

Starting with a (m,n,n) numpy array, lets say I want to apply some function to every (n,n) sub-array without using a for-loop.

The two functions I'd like to implement would be to first use np.multiply to element-wise multiply (not regular matrix multiplication) another (n,n) array with each (n,n) sub-array. Then I'd like to use np.sum to sum each resulting (n,n) sub-arrays to get an array of length m containing only those sums.

Is there a general way to apply a function to each sub-array without looping through the m index?

0

There are 0 best solutions below