Skip to main content
Functions prefixed with linalg. live under the linalg namespace (e.g., np.linalg.norm(...)). Functions without the prefix are top-level (e.g., np.trace(...)).

linalg.norm

Compute the norm of a matrix or vector. The behavior depends on the ord parameter and the dimensions of the input.
Returns: number | NDArray — Scalar when computing the norm of the entire array; NDArray when computing along axes.

linalg.matrix_norm

Compute a matrix norm. This is a convenience function equivalent to linalg.norm with a 2-D input.
Returns: number | NDArray — For a single matrix returns a scalar. For batch input [..., M, N] returns NDArray with shape [...].

linalg.vector_norm

Compute a vector norm. This is a convenience function for computing norms along specific axes.
Returns: number | NDArray — The vector norm.

linalg.cond

Compute the condition number of a matrix. A large condition number indicates the matrix is close to singular.
Returns: number — The condition number.

linalg.det

Compute the determinant of a square matrix.
Returns: number — The determinant.

linalg.slogdet

Compute the sign and natural logarithm of the determinant. This is more numerically stable than computing det directly for matrices with very large or very small determinants.
Returns: { sign, logabsdet } — For a single matrix, sign is -1, 0, or 1 and logabsdet is the natural log of the absolute value of the determinant. The determinant is sign * exp(logabsdet). For a batch input [..., n, n], both sign and logabsdet are NDArray with shape [...].

linalg.matrix_rank

Compute the rank of a matrix using SVD. Singular values below a threshold are treated as zero.
Returns: number — The effective rank.

trace

Return the sum along diagonals of the array. For a 2-D array, this returns the sum of the diagonal elements. For higher-dimensional arrays, the axes along which the diagonal is taken can be specified. Also available as np.linalg.trace(...).
Returns: number | NDArray — Scalar for 2-D input, NDArray for higher-dimensional input.

diagonal

Return the specified diagonal of an array. For a 2-D array, returns the diagonal elements. For higher-dimensional arrays, the diagonal is taken over the specified axes. Also available as np.linalg.diagonal(...).
Returns: NDArray — The extracted diagonal.

cross

Compute the cross product of two vectors. For 3-D vectors, this returns a 3-D vector. For 2-D vectors, this returns the scalar z-component. Also available as np.linalg.cross(...).
Returns: NDArray — The cross product. For 3-D inputs: a 3-D vector. For 2-D inputs: a scalar (the z-component).