bundles / scipy latest / scipy / linalg / _basic / solve
function
scipy.linalg._basic:solve
source: /scipy/linalg/_basic.py :99
Signature
def solve ( a , b , lower = False , overwrite_a = False , overwrite_b = False , check_finite = True , assume_a = None , transposed = False ) Summary
Solve the equation a @ x = b for x, where a is a square matrix.
Extended Summary
If the data matrix is known to be a particular type then supplying the corresponding string to assume_a key chooses the dedicated solver. The available options are
============================= ================================ diagonal 'diagonal' tridiagonal 'tridiagonal' banded 'banded' upper triangular 'upper triangular' lower triangular 'lower triangular' symmetric 'symmetric' (or 'sym') hermitian 'hermitian' (or 'her') symmetric positive definite 'positive definite' (or 'pos') general 'general' (or 'gen') ============================= ================================
Array argument(s) of this function may have additional "batch" dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see linalg_batch for details.
Parameters
a: array_like, shape (..., N, N)Square left-hand side matrix or a batch of matrices.
b: (..., N, NRHS) array_likeInput data for the right hand side or a batch of right-hand sides.
lower: bool, default: FalseIgnored unless
assume_ais one of'sym','her', or'pos'. If True, the calculation uses only the data in the lower triangle ofa; entries above the diagonal are ignored. If False (default), the calculation uses only the data in the upper triangle ofa; entries below the diagonal are ignored.overwrite_a: bool, default: FalseAllow overwriting data in
a(may enhance performance).overwrite_b: bool, default: FalseAllow overwriting data in
b(may enhance performance).check_finite: bool, default: TrueWhether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
assume_a: str, optionalValid entries are described above. If omitted or
None, checks are performed to identify structure so the appropriate solver can be called.transposed: bool, default: FalseIf True, solve
a.T @ x == b. RaisesNotImplementedErrorfor complexa.
Returns
x: ndarray, shape (N, NRHS) or (..., N)The solution array.
Raises
: ValueErrorIf size mismatches detected or input a is not square.
: LinAlgErrorIf the computation fails because of matrix singularity.
: LinAlgWarningIf an ill-conditioned input a is detected.
: NotImplementedErrorIf transposed is True and input a is a complex matrix.
Notes
If the input b matrix is a 1-D array with N elements, when supplied together with an NxN input a, it is assumed as a valid column vector despite the apparent size mismatch. This is compatible with the numpy.dot() behavior and the returned result is still 1-D array.
The general, symmetric, Hermitian and positive definite solutions are obtained via calling ?GETRF/?GETRS, ?SYSV, ?HESV, and ?POTRF/?POTRS routines of LAPACK respectively.
The datatype of the arrays define which solver is called regardless of the values. In other words, even when the complex array entries have precisely zero imaginary parts, the complex solver will be called based on the data type of the array.
Examples
Given `a` and `b`, solve for `x`:import numpy as np a = np.array([[3, 2, 0], [1, -1, 0], [0, 5, 1]]) b = np.array([2, 4, -1]) from scipy.linalg import solve x = solve(a, b) x✓
a @ x == b
✗a = np.arange(12).reshape(3, 2, 2) # a batch of 3 2x2 matrices A = a.transpose(0, 2, 1) @ a # A is a batch of 3 positive definite matrices b = np.ones(2) solve(A, b) # this automatically detects that A is pos.def. solve(A, b, assume_a='pos') # bypass structucture detection✓
Aliases
-
scipy.linalg.solve
Referenced by
This package
Other packages
- numpy reference:routines.linalg
- numpy reference:routines.linalg
- numpy reference:routines.linalg