xorbits.numpy.linalg.solve#
- xorbits.numpy.linalg.solve(a, b, sym_pos=False, sparse=None)[源代码]#
Solve a linear matrix equation, or system of linear scalar equations.
Computes the “exact” solution, x, of the well-determined, i.e., full rank, linear matrix equation ax = b.
- 参数
a ((..., M, M) array_like) – Coefficient matrix.
b ({(..., M,), (..., M, K)}, array_like) – Ordinate or “dependent variable” values.
- 返回
x – Solution to the system a x = b. Returned shape is identical to b.
- 返回类型
{(…, M,), (…, M, K)} ndarray
- 引发
LinAlgError – If a is singular or not square.
参见
scipy.linalg.solve
Similar function in SciPy.
提示
1.8.0(numpy.linalg) 新版功能.
Broadcasting rules apply, see the numpy.linalg documentation for details.
The solutions are computed using LAPACK routine
_gesv
.a must be square and of full-rank, i.e., all rows (or, equivalently, columns) must be linearly independent; if either is not true, use lstsq for the least-squares best “solution” of the system/equation.
引用
- 1
G. Strang, Linear Algebra and Its Applications, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pg. 22.
实际案例
Solve the system of equations
x0 + 2 * x1 = 1
and3 * x0 + 5 * x1 = 2
:>>> a = np.array([[1, 2], [3, 5]]) >>> b = np.array([1, 2]) >>> x = np.linalg.solve(a, b) >>> x array([-1., 1.])
Check that the solution is correct:
>>> np.allclose(np.dot(a, x), b) True
- sym_posbool
Assume a is symmetric and positive definite. If
True
, use Cholesky decomposition.- sparse: bool, optional
Return sparse value or not.
This docstring was copied from numpy.linalg.