Search code examples
pythonnumpydeterminants

Determinant over a specific axis using numpy


Suppose I have a numpy array A with shape (j,d,d) and I want to obtain an array with shape j, in which each entry corresponds to the determinant of each (d,d) array.

I tried using np.apply_along_axis(np.linalg.det(A), axis=0), but np.apply_along_axis only seems to work for 1D slices.

Is there an efficient way of doing that using only numpy?


Solution

  • np.linalg.det can already do this for an array of arbitrary shape as long as the last two dimensions are square. You can see the documentation here.