python中numpy計算數組的行列式numpy.linalg.det()


numpy.linalg.det

numpy.linalg.det(a)[source]

計算任何一個數組a的行列式,但是這里要求數組的最后兩個維度必須是方陣。

參數:

a : (..., M, M) array_like

Input array to compute determinants for.

返回:

det : (...) array_like

Determinant of a.

 

 

 

 

 

 

 

例如:

 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.])

其實這個函數就是為了計算方陣的行列式值的。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM