Skip to main content
All functions on this page live under the linalg namespace. Access them as np.linalg.solve(...), np.linalg.inv(...), etc.

linalg.solve

Solve the linear matrix equation Ax = b for x. The matrix a must be square and non-singular.
Returns: NDArray — Solution x such that A @ x = b. Throws: Error if a is singular or not square.

linalg.lstsq

Compute the least-squares solution to a linear matrix equation. Finds x that minimizes ||b - Ax||^2. Works for overdetermined and underdetermined systems.
Returns: { x, residuals, rank, s } where:
  • x — Least-squares solution of shape [N] or [N, K].
  • residuals — Sum of squared residuals (empty if rank < N or M <= N).
  • rank — Effective rank of a.
  • s — Singular values of a in descending order.

linalg.inv

Compute the multiplicative inverse of a square matrix. The result satisfies A @ A_inv = I.
Returns: NDArray — The inverse matrix of shape [N, N]. Throws: Error if the matrix is singular.

linalg.pinv

Compute the Moore-Penrose pseudo-inverse of a matrix. This generalizes the inverse to non-square and singular matrices.
Returns: NDArray — The pseudo-inverse of shape [..., N, M].

linalg.tensorinv

Compute the inverse of an N-dimensional array. The inverse is defined such that tensordot(a_inv, a, ind) = I, where I is the identity operator.
Returns: NDArray — The tensor inverse.

linalg.tensorsolve

Solve the tensor equation a x = b for x. This is the tensor generalization of linalg.solve.
Returns: NDArray — The solution tensor x.

linalg.multi_dot

Compute the dot product of two or more arrays in a single call, automatically optimizing the order of multiplications (using the optimal parenthesization) to minimize the number of scalar multiplications.
Returns: NDArray — The dot product of all the input arrays.

linalg.matrix_power

Raise a square matrix to an integer power. For positive n, this computes a @ a @ ... @ a (n times). For n = 0, returns the identity. For negative n, computes the inverse raised to |n|.
Returns: NDArray — The matrix a raised to the power n.