在Python中使用奇异值分解方法返回完全秩矩阵的秩

在Python中使用奇异值分解方法返回完全秩矩阵的秩

要使用奇异值分解方法返回数组的秩,请在Python中使用numpy.linalg.matrix_rank()方法。数组的秩是大于tol的奇异值的数量。第一个参数A是输入向量或矩阵堆栈。

第二个参数tol是被认为为零的阈值以下的SVD值。如果tol为None,并且S是M的奇异值数组,并且eps是S的数据类型的epsilon值,则tol被设置为S.max() * max(M, N) * eps。第三个参数hermitian,如果为True,则假定A是Hermitian矩阵,从而使查找奇异值的方法更高效。默认为False。

步骤

首先,导入所需的库−

import numpy as np
from numpy.linalg import 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.linalg.matrix_rank()方法 –

print("\nRank (Full-Rank Matrix)...\n",matrix_rank(arr))

示例

import numpy as np
from numpy.linalg import matrix_rank

# Create an array
arr = np.eye(5)

# 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 return matrix rank of array using Singular Value Decomposition method, use the numpy.linalg.matrix_rank() method in Python
print("\nRank (Full-Rank Matrix)...\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)

Rank (Full-Rank Matrix)...
5

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程