linalg namespace. Access them as np.linalg.solve(...), np.linalg.inv(...), etc.
linalg.solve
Solve the linear matrix equationAx = b for x. The matrix a must be square and non-singular.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Coefficient matrix of shape [N, N]. |
b | ArrayLike | — | Right-hand side vector or matrix. Shape [N] for a single system or [N, M] for multiple right-hand sides. |
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. Findsx that minimizes ||b - Ax||^2. Works for overdetermined and underdetermined systems.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Coefficient matrix of shape [M, N]. |
b | ArrayLike | — | Right-hand side of shape [M] or [M, K]. |
rcond | number | -1 | Cut-off ratio for small singular values. Singular values less than rcond * largest_sv are treated as zero. A value of -1 uses machine precision. |
{ x, residuals, rank, s } where:
x— Least-squares solution of shape[N]or[N, K].residuals— Sum of squared residuals (empty ifrank < NorM <= N).rank— Effective rank ofa.s— Singular values ofain descending order.
linalg.inv
Compute the multiplicative inverse of a square matrix. The result satisfiesA @ A_inv = I.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input square matrix of shape [N, N]. |
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.| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input matrix of shape [M, N]. |
rcond | number | 1e-15 | Cutoff for small singular values. Singular values less than rcond * max(sv) are set to zero. |
NDArray — The pseudo-inverse of shape [N, M].
linalg.tensorinv
Compute the inverse of an N-dimensional array. The inverse is defined such thattensordot(a_inv, a, ind) = I, where I is the identity operator.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input tensor to invert. |
ind | number | 2 | Number of first indices that are involved in the inverse sum. Must satisfy prod(a.shape[:ind]) == prod(a.shape[ind:]). |
NDArray — The tensor inverse.
linalg.tensorsolve
Solve the tensor equationa x = b for x. This is the tensor generalization of linalg.solve.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Coefficient tensor. |
b | ArrayLike | — | Right-hand side tensor. |
axes | number[] | undefined | Axes in a to reorder to the right before solving. |
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.| Name | Type | Default | Description |
|---|---|---|---|
arrays | ArrayLike[] | — | Array of matrices to multiply. The first and last can be 1-D (treated as row/column vectors). |
NDArray — The dot product of all the input arrays.
linalg.matrix_power
Raise a square matrix to an integer power. For positiven, this computes a @ a @ ... @ a (n times). For n = 0, returns the identity. For negative n, computes the inverse raised to |n|.
| Name | Type | Default | Description |
|---|---|---|---|
a | ArrayLike | — | Input square matrix. |
n | number | — | Integer exponent. Can be positive, zero, or negative. |
NDArray — The matrix a raised to the power n.