在 Python 中计算线性代数中矩阵的行列式
如需计算线性代数中矩阵的行列式,请在 Python Numpy 中使用 np.linalg.det()。第一个参数 a 是要计算行列式的输入矩阵。该方法返回行列式。
步骤
首先,导入必需的模块 -
import numpy as np
创建一个矩阵 −
arr = np.array([[ 5, 10], [12, 18]])
显示矩阵 −
print("Our Array...\n",arr)检查矩阵的维度 −
print("\nDimensions of our Array...\n",arr.ndim)获取矩阵的数据类型 −
print("\nDatatype of our Array object...\n",arr.dtype)获取矩阵的形状 −
print("\nShape of our Array object...\n",arr.shape)如需计算线性代数中矩阵的行列式,请在 Python Numpy 中使用 np.linalg.det() −
print("\nResult (determinant)...\n",np.linalg.det(arr))示例
import numpy as np
# Create an array
arr = np.array([[ 5, 10], [12, 18]])
# Display the array
print("Our Array...\n",arr)
# Check the Dimensions
print("\nDimensions of our Array...\n",arr.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",arr.dtype)
# Get the Shape
print("\nShape of our Array object...\n",arr.shape)
# To Compute the determinant of an array in linear algebra, use the np.linalg.det() in Python Numpy.
print("\nResult (determinant)...\n",np.linalg.det(arr))输出
Our Array... [[ 5 10] [12 18]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result (determinant)... -30.000000000000014
广告
数据结构
计算机网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP