I have several arrays in a list (think of it as a time series):
one_array = np.array([[1, 2, 3],[5,5,5],[0,0,1]])
many_arrays = np.array([one_array, one_array + 1])
Now, I want to do the same operation for every matrix in the time series, e.g. I want to calculate the determinant. These two operations give the same result (-5
):
np.linalg.det(one_array)
np.linalg.det(many_arrays[0,:,:])
How do I tell Python to do np.linalg.det(many_arrays[i,:,:]) for every i
without used the dreaded loop? So in this particular example I'd like to get (-5, -6)
as a return value.
Bonus points: How can I tell Python to do np.linalg.det(even_more_arrays[i, j, :,:]) for every i, j
?
edit: I am looking for a generic way to do this. I understand that np.linalg.det supports this operation. But how do I do it for any function DO_SOMETHING_WITH_2D_MATRIX
that only takes a 2 dimensional object:
DO_SOMETHING_WITH_2D_MATRIX(one_array)
DO_SOMETHING_WITH_2D_MATRIX(many_arrays[0,:,:])