Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python에서 Singular Value Decomposition 방법을 사용하여 배열의 행렬 순위 반환

<시간/>

Singular Value Decomposition 메서드를 사용하여 배열의 행렬 순위를 반환하려면 Python에서 numpy.linalg.matrix_rank() 메서드를 사용합니다. 배열의 순위는 tol보다 큰 배열의 특이값 개수입니다. 첫 번째 매개변수인 A는 입력 벡터 또는 행렬 스택입니다.

두 번째 매개변수인 tol은 SVD 값이 0으로 간주되는 임계값입니다. tol이 None이고 S가 M에 대한 특이값이 있는 배열이고 eps가 S의 데이터 유형에 대한 엡실론 값이면 tol은 S.max() * max(M, N) * eps로 설정됩니다. 세 번째 매개변수인 Hermitian, If 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)

Singular Value Decomposition 메서드를 사용하여 배열의 행렬 순위를 반환하려면 Python에서 numpy.linalg.matrix_rank() 메서드를 사용하십시오 -

print("\nResult (rank)...\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("\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