使用 SciPy 库计算方阵的行列式


矩阵的行列式,表示为 |A|,是一个可以从方阵计算出的标量值。借助矩阵的行列式,我们可以求出矩阵的逆以及在方程组、微积分等方面实用的其他内容。scipy.linalg.det() 命名的函数用于计算方阵的行列式。

让我们通过以下给定的示例理解一下这一点 −

示例

计算 2 × 2 矩阵的行列式

#Importing the scipy package
import scipy

#Importing the numpy package
import numpy as np

#Declaring the numpy array (Square Matrix)
X = np.array([[5,1],[8,4]])

#Passing the values to scipy.linalg.det() function
M = scipy.linalg.det(X)

#Printing the result
print('Determinant of 
{}
is {}'.format(X,M))

输出

Determinant of
[[5 1]
[8 4]]
is 12.0

示例

计算 3 × 3 矩阵的行列式

import scipy
import numpy as np
Y = np.array([[1,2,9],[5,4,3],[1,5,3]])
M = scipy.linalg.det(Y)
print('Determinant of 
{}
is {}'.format(Y,M))

输出

Determinant of
[[1 2 9]
[5 4 3]
[1 5 3]]
is 162.0

更新于:2021 年 11 月 24 日

360 次浏览

开启您的 职业

完成课程获得认证

开始学习
广告
© . All rights reserved.