python中numpy計算數組的行列式numpy.linalg.det()
阿新 • • 發佈:2017-12-29
shape array dimens arr style 數組 -name ons github
numpy.linalg.det
numpy.linalg.
det
(a)[source]
計算任何一個數組a的行列式,但是這裏要求數組的最後兩個維度必須是方陣。
參數: |
a : (..., M, M) array_like
|
---|---|
返回: |
det : (...) array_like
|
例如:
1 >>>a=np.reshape(np.arange(6),(2,3)) 2 >>>a 3 out:array([[0, 1, 2],4 [3, 4, 5]]) 5 >>>np.linalg.det(a) 6 out:LinAlgError: Last 2 dimensions of the array must be square 7 8 >>>a=np.reshape(np.arange(20),(5,2,2)) 9 >>>a 10 out:array([[[ 0, 1], 11 [ 2, 3]], 12 13 [[ 4, 5], 14 [ 6, 7]], 15 16 [[ 8, 9],17 [10, 11]], 18 19 [[12, 13], 20 [14, 15]], 21 22 [[16, 17], 23 [18, 19]]]) 24 25 >>>np.linalg.det(a) 26 out:array([-2., -2., -2., -2., -2.])
其實這個函數就是為了計算方陣的行列式值的。
python中numpy計算數組的行列式numpy.linalg.det()