矩阵的Python的逆 [英] Python Inverse of a Matrix

查看:618
本文介绍了矩阵的Python的逆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在python一个矩阵的逆?我已经实现了它自己,但它是纯Python,我怀疑有更快的模块,在那里做了。

How do I get the inverse of a matrix in python? I've implemented it myself, but it's pure python, and I suspect there are faster modules out there to do it.

推荐答案

您应该看一看 numpy的如果你做矩阵操纵。这是一个模块主要由C,这将是比纯Python编程快得多。下面是如何反转矩阵,和做其他矩阵操作的例子。

You should have a look at numpy if you do matrix manipulation. This is a module mainly written in C, which will be much faster than programming in pure python. Here is an example of how to invert a matrix, and do other matrix manipulation.

from numpy import matrix
from numpy import linalg
A = matrix( [[1,2,3],[11,12,13],[21,22,23]]) # Creates a matrix.
x = matrix( [[1],[2],[3]] )                  # Creates a matrix (like a column vector).
y = matrix( [[1,2,3]] )                      # Creates a matrix (like a row vector).
print A.T                                    # Transpose of A.
print A*x                                    # Matrix multiplication of A and x.
print A.I                                    # Inverse of A.
print linalg.solve(A, x)     # Solve the linear equation system.

您还可以看看在阵列的模块,这是当你要处理的只有一个数据类型更加高效的执行列表。

You can also have a look at the array module, which is a much more efficient implementation of lists when you have to deal with only one data type.

这篇关于矩阵的Python的逆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆