📜  Python中的 numpy.linalg.det() 方法

📅  最后修改于: 2022-05-13 01:55:14.905000             🧑  作者: Mango

Python中的 numpy.linalg.det() 方法

在 NumPy 中,我们可以借助numpy.linalg.det() 计算给定方阵的行列式。它将给定的方数组作为参数并返回其行列式。

示例 1:

Python
import numpy as np
from numpy import linalg as LA
 
 
array1 = np.array([[1, 2], [3, 4]])
 
# Original 2-d array
print(array1)
 
# Determinant of the said 2-D array
print(np.linalg.det(array1))


Python
import numpy as np
from numpy import linalg as LA
 
 
array1 = np.array([[1, 2, 3], [3, 4, 1], [3, 2, 1]])
 
# Original 2-d array
print(array1)
 
# Determinant of the said 2-D array
print(np.linalg.det(array1))


输出:

[[1 2]
 [3 4]]
-2.0000000000000004

示例 2:

Python

import numpy as np
from numpy import linalg as LA
 
 
array1 = np.array([[1, 2, 3], [3, 4, 1], [3, 2, 1]])
 
# Original 2-d array
print(array1)
 
# Determinant of the said 2-D array
print(np.linalg.det(array1))

输出:

[[1 2 3]
 [3 4 1]
 [3 2 1]]
-15.999999999999998