- 教程
- 介绍
- 环境
- Ndarray 对象(Ndarray Object)
- 数据类型
- 数组属性(Array Attributes)
- 阵列创建例程(Array Creation Routines)
- 来自现有数据的数组(Array from Existing Data)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 广播(Broadcasting)
- 迭代数组(Iterating Over Array)
- 数组操作(Array Manipulation)
- Binary 运算符
- 字符串函数(String Functions)
- 数学函数(Mathematical Functions)
- 算术运算(Arithmetic Operations)
- 统计函数(Statistical Functions)
- 统计函数(Statistical Functions)
- 字节交换(Byte Swapping)
- 副本和视图(Copies & Views)
- 矩阵库(Matrix Library)
- 线性代数(Linear Algebra)
- Matplotlib(Matplotlib)
- 使用Matplotlib的直方图(Histogram Using Matplotlib)
- I/O with NumPy
- 有用的资源
- reshape
- flat
- flatten
- ravel
- transpose
- ndarray.T
- rollaxis
- swapaxes
- broadcast
- broadcast_to
- expand_dims
- squeeze
- concatenate
- stack
- hstack
- vstack
- split
- hsplit
- vsplit
- resize
- append
- insert
- delete
- unique
- bitwise_and
- bitwise_or
- invert
- left_shift
- right_shift
- add()
- multiply()
- center()
- capitalize()
- title()
- lower()
- upper()
- split()
- splitlines()
- strip()
- join()
- replace()
- decode()
- encode()
- dot
- vdot
- inner
- matmul
- determinant
- solve
- inv
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
inv
我们使用numpy.linalg.inv()函数来计算矩阵的逆。 矩阵的逆是这样的,如果它乘以原始矩阵,则得到单位矩阵。
例子 (Example)
import numpy as np
x = np.array([[1,2],[3,4]])
y = np.linalg.inv(x)
print x
print y
print np.dot(x,y)
它应该产生以下输出 -
[[1 2]
[3 4]]
[[-2. 1. ]
[ 1.5 -0.5]]
[[ 1.00000000e+00 1.11022302e-16]
[ 0.00000000e+00 1.00000000e+00]]
例子 (Example)
现在让我们在我们的例子中创建一个矩阵A的逆。
import numpy as np
a = np.array([[1,1,1],[0,2,5],[2,5,-1]])
print 'Array a:”
print a
ainv = np.linalg.inv(a)
print 'Inverse of a:'
print ainv
print 'Matrix B is:'
b = np.array([[6],[-4],[27]])
print b
print 'Compute A-1B:'
x = np.linalg.solve(a,b)
print x
# this is the solution to linear equations x = 5, y = 3, z = -2
它将产生以下输出 -
Array a:
[[ 1 1 1]
[ 0 2 5]
[ 2 5 -1]]
Inverse of a:
[[ 1.28571429 -0.28571429 -0.14285714]
[-0.47619048 0.14285714 0.23809524]
[ 0.19047619 0.14285714 -0.0952381 ]]
Matrix B is:
[[ 6]
[-4]
[27]]
Compute A-1B:
[[ 5.]
[ 3.]
[-2.]]
使用该功能可以获得相同的结果 -
x = np.dot(ainv,b)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论