Python 求逆矩阵
时间: 2023-10-29 22:53:18 浏览: 94
在Python中,可以使用numpy库中的linalg.inv()函数来求解矩阵的逆。首先,将原始矩阵作为参数传递给inv()函数,它将返回原始矩阵的逆矩阵。以下是一个示例代码:
```python
import numpy as np
M = np.array(\[\[1, 2, -1\], \[2, 3, 4\], \[3, 1, 2\]\])
inverse_M = np.linalg.inv(M)
print(inverse_M)
```
这段代码将打印出原始矩阵的逆矩阵。请注意,如果原始矩阵不可逆(奇异矩阵),则会引发LinAlgError异常。因此,在实际应用中,我们应该先检查矩阵是否可逆。
#### 引用[.reference_title]
- *1* [Python——矩阵求逆、矩阵的转置](https://blog.csdn.net/m0_72662900/article/details/126028432)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [python求矩阵的逆](https://blog.csdn.net/weixin_43905191/article/details/104695990)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文