在 Python 线性代数中计算矩阵堆栈的行列式
若要计算线性代数中矩阵堆栈的行列式,请在 Python Numpy 中使用 np.linalg.det()。第 1 个参数 a 是计算行列式的输入数组。该方法返回 a 的行列式。
步骤
首先,导入所需的库 -
import numpy as np
创建一个数组 −
arr = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ])
显示数组 −
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 中使用 np.linalg.det() −
print("\nResult (determinant)...\n",np.linalg.det(arr))示例
import numpy as np
# Create an array
arr = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]]])
# 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 for a stack of matrices in linear algebra, use the np.linalg.det() in Python Numpy.
print("\nResult (determinant)...\n",np.linalg.det(arr))输出
Our Array... [[[1 2] [3 4]] [[1 2] [2 1]] [[1 3] [3 1]]] Dimensions of our Array... 3 Datatype of our Array object... int64 Shape of our Array object... (3, 2, 2) Result (determinant)... [-2. -3. -8.]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP