要使用奇异值分解方法返回数组的矩阵秩,请使用 numpy. Python中的方法。数组的秩是数组中大于 tol 的奇异值的数量。第一个参数 A 是输入向量或矩阵堆栈。linalg.matrix_rank()
第二个参数 tol 是阈值,低于该阈值的 SVD 值被视为零。如果 tol 为 None,并且 S 是 M 具有奇异值的数组,并且 eps 是 S 的数据类型的 epsilon 值,则 tol 设置为* * eps。第三个参数 Hermitian,如果为真,则假定 A 为 Hermitian,从而可以更有效地找到奇异值。默认为假。S.max()max(M, N)
脚步
首先,导入所需的库 -
import numpy as np fromnumpy.linalgimport matrix_rank
创建一个数组 -
arr = np.eye(5)
显示数组 -
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)
要使用奇异值分解方法返回数组的矩阵秩,请使用 numpy. Python中的方法 -linalg.matrix_rank()
print("\nResult (rank)...\n",matrix_rank(arr))
示例
import numpy as np fromnumpy.linalgimport matrix_rank #创建一个数组 arr = np.eye(5) #显示数组 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.linalg.matrix_rank() 方法 print("\nResult (rank)...\n",matrix_rank(arr))输出结果
Our Array... [[1. 0. 0. 0. 0.] [0. 1. 0. 0. 0.] [0. 0. 1. 0. 0.] [0. 0. 0. 1. 0.] [0. 0. 0. 0. 1.]] Dimensions of our Array... 2 Datatype of our Array object... float64 Shape of our Array object... (5, 5) Result (rank)... 5