如何计算向量的伪逆以及行列式?(最好使用 numpy 或更好的 pandas)
我试过这个但它不起作用:
import numpy
vect = [1, 2, 3, 4]
numpy.linalg.pinv(vect)
但我得到这个错误:
---------------------------------------------------------------------------
LinAlgError Traceback (most recent call last)
<ipython-input-106-e362654e383f> in <module>()
19 vect = [1, 2, 3, 4]
---> 20 print(np.linalg.pinv(vect))
C:\Python27\lib\site-packages\numpy\linalg\linalg.pyc in pinv(a, rcond)
1544 _assertNonEmpty(a)
1545 a = a.conjugate()
-> 1546 u, s, vt = svd(a, 0)
1547 m = u.shape[0]
1548 n = vt.shape[1]
C:\Python27\lib\site-packages\numpy\linalg\linalg.pyc in svd(a, full_matrices, compute_uv)
1269 """
1270 a, wrap = _makearray(a)
-> 1271 _assertRank2(a)
1272 _assertNonEmpty(a)
1273 m, n = a.shape
C:\Python27\lib\site-packages\numpy\linalg\linalg.pyc in _assertRank2(*arrays)
153 if len(a.shape) != 2:
154 raise LinAlgError, '%d-dimensional array given. Array must be \
--> 155 two-dimensional' % len(a.shape)
156
157 def _assertSquareness(*arrays):
LinAlgError: 1-dimensional array given. Array must be two-dimensional