Python pseudo inverse and determinant of a vector
linear-algebra, numpy, pandas, python, vector
Solution
Perhaps you want this?
>>> np.linalg.pinv([[1, 2, 3, 4]])
array([[ 0.03333333],
[ 0.06666667],
[ 0.1 ],
[ 0.13333333]])
Note the extra set of brackets. As the error message suggests, you can only take the pseudo-inverse of a matrix. If you just have a vector you need to make it into a 1-row matrix.
Problem
How to compute the pseudo inverse of a vector and also the determinant? (preferably with either numpy, or better pandas) I tried this but it doesn't work: ``` import numpy vect = [1, 2, 3, 4] numpy.linalg.pinv(vect) ``` But I get this error: ``` --------------------------------------------------------------------------- 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 ```