要计算线性代数中数组的行列式,请使用 np. 在 Python Numpy 中。第一个参数 a 是计算行列式的输入数组。该方法返回行列式。linalg.det()
脚步
首先,导入所需的库 -
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)
要计算线性代数中数组的行列式,请使用 np. 在 Python Numpy 中 -linalg.det()
print("\nResult (determinant)...\n",np.linalg.det(arr))
示例
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))输出结果
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