赞
踩
函数 | 说明 |
det(ndarray) | 计算矩阵列式 |
eig(ndarray) | 计算方阵的本征值和本征向量 |
inv(ndarray) pinv(ndarray) | 计算方阵的逆 计算方阵的Moore-Penrose伪逆 |
qr(ndarray) | 计算qr分解 |
svd(ndarray) | 计算奇异值分解svd |
solve(ndarray) | 解线性方程组Ax = b,其中A为方阵 |
lstsq(ndarray) | 计算Ax=b的最小二乘解 |
det计算方阵的行列式
- #det(ndarray) 计算方阵的矩阵列式
- a = np.array([[1,6,7],
- [2,5,3],
- [3,4,1]])
- ret = np.linalg.det(a) #-14
- a = np.array([[1,2,3],
- [6,5,4],
- [7,6,5]])
- ret = np.linalg.eig(a) #本征值,本征向量
- print(ret[0]) #[ 1.27284161e+01 -1.72841615e+00 1.90757877e-16]
- print(ret[1]) #[[ 0.29245036 0.78800111 0.40824829]
- # [ 0.60875015 -0.45826232 -0.81649658]
- # [ 0.73749308 -0.41115678 0.40824829]]
- a = np.array([[1,2,3],
- [4,5,6],
- [7,8,9]])
- ai = np.linalg.inv(a)
- print(ai)
- print(ai.shape)
- '''
- [[ -4.50359963e+15 9.00719925e+15 -4.50359963e+15]
- [ 9.00719925e+15 -1.80143985e+16 9.00719925e+15]
- [ -4.50359963e+15 9.00719925e+15 -4.50359963e+15]]
- (3, 3)
- '''
- api = np.linalg.pinv(a)
- print(api)
- print(api.shape)
- '''
- [[ -6.38888889e-01 -1.66666667e-01 3.05555556e-01]
- [ -5.55555556e-02 3.46944695e-17 5.55555556e-02]
- [ 5.27777778e-01 1.66666667e-01 -1.94444444e-01]]
- (3, 3)
- '''
- a = np.array([[1,2,3],
- [4,5,6],
- [7,8,9]])
- aqr = np.linalg.qr(a)
- print(aqr)
- '''
- (array([[-0.12309149, 0.90453403, 0.40824829],
- [-0.49236596, 0.30151134, -0.81649658],
- [-0.86164044, -0.30151134, 0.40824829]]),
- array([[ -8.12403840e+00, -9.60113630e+00, -1.10782342e+01],
- [ 0.00000000e+00, 9.04534034e-01, 1.80906807e+00],
- [ 0.00000000e+00, 0.00000000e+00, -7.58790979e-16]]))
- '''
- asvd = np.linalg.svd(a)
- print(asvd)
- '''
- (array([[-0.21483724, 0.88723069, 0.40824829],
- [-0.52058739, 0.24964395, -0.81649658],
- [-0.82633754, -0.38794278, 0.40824829]]),
- array([ 1.68481034e+01, 1.06836951e+00, 4.41842475e-16]),
- array([[-0.47967118, -0.57236779, -0.66506441],
- [-0.77669099, -0.07568647, 0.62531805],
- [-0.40824829, 0.81649658, -0.40824829]]))
- '''
- a = np.array([[1,2,3],
- [4,5,6],
- [7,8,9]])
- b = np.array([0,2,6])
- ret = np.linalg.solve(a,b)
- print(ret)
- '''
- (array([[-0.21483724, 0.88723069, 0.40824829],
- [-0.52058739, 0.24964395, -0.81649658],
- [-0.82633754, -0.38794278, 0.40824829]]),
- array([ 1.68481034e+01, 1.06836951e+00, 4.41842475e-16]),
- array([[-0.47967118, -0.57236779, -0.66506441],
- [-0.77669099, -0.07568647, 0.62531805],
- [-0.40824829, 0.81649658, -0.40824829]]))
- [ -9.00719925e+15 1.80143985e+16 -9.00719925e+15]
- '''
- a = np.array([[1,2,3],
- [4,5,6],
- [7,8,9]])
- b = np.array([0,2,6])
- ret = np.linalg.lstsq(a,b)
- print('lstsq:\n',ret)
- '''
- lstsq:
- (array([ 1.5 , 0.33333333, -0.83333333]),
- array([], dtype=float64), 2,
- array([ 1.68481034e+01, 1.06836951e+00, 4.41842475e-16]))
- '''
(end)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。