---
title: linalg.solve
description: "求解线性矩阵方程或线性标量方程组。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_kml_16_0549.html
sourcePath: /source/zh/kunpengboostkithistory/240RC1/accel/kunpengaccel_kml_16_0549.html
indexId: 3a7510eafa040e1c5ad2837b350e6e7b1733932f98a6efba443881116f2dbf5076
---
# linalg.solve

#### 功能描述

求解线性矩阵方程或线性标量方程组。

计算确定的“精确”解x，即满秩线性矩阵方程ax = b


#### 必选输入参数

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| a | (…,M,M) array\_like | 系数矩阵。 |
| b | {(…,M,),(…,M,K)}, array\_like | 纵坐标或“因变量”值。 |


#### 可选输入参数

无。


#### 返回数据

| 类型 | 说明 |
| --- | --- |
| {(…, M,), (…, M, K)} ndarray | 方程组ax = b的解，返回的大小与b相同。 |


#### 示例

```
>>> import numpy as np
>>> # 解方程 x0 + 2*x1 = 1, 3*x0 + 5*x1 = 2
>>> a = np.array([[1,2],[3,5]])
>>> a
array([[1, 2],
[3, 5]])
>>> b = np.array([1,2])
>>> b
array([1, 2])
>>>
>>> x = np.linalg.solve(a, b)
>>> x
array([-1.,  1.])
>>>
>>> np.allclose(np.dot(a,x), b)
True
>>>
```
