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

Python의 선형 대수학에서 촐레스키 분해 반환

<시간/>

Cholesky 분해를 반환하려면 numpy.linalg.cholesky() 메서드를 사용합니다. 정방행렬 a의 촐레스키 분해 L * L.H를 반환합니다. 여기서 L은 하부삼각형이고 .H는 켤레 전치 연산자입니다. 에르미트 및 양의 정부호여야 합니다. Hermitian인지 아닌지 확인하기 위한 검사는 수행되지 않습니다. 또한 의 하부 삼각 요소와 대각선 요소만 사용됩니다. 실제로 L만 반환됩니다.

그러면 매개변수 a는 에르미트(모든 요소가 실수인 경우 대칭), 양의 정부호 입력 행렬입니다. 이 방법은 의 상부 또는 하부 삼각 촐레스키 인수를 반환합니다. 행렬 객체인 경우 행렬 객체를 반환합니다.

단계

먼저 필요한 라이브러리를 가져옵니다. -

import numpy as np

numpy.array() 메서드를 사용하여 2D numpy 배열 만들기 -

arr = np.array([[1,-2j],[2j,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)

Cholesky 분해를 반환하려면 numpy.linalg.cholesky() 메서드를 사용하십시오 -

print("\nCholesky decomposition in Linear Algebra...\n",np.linalg.cholesky(arr))

예시

import numpy as np

# Creating a 2D numpy array using the numpy.array() method
arr = np.array([[1,-2j],[2j,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 the Cholesky decomposition, use the numpy.linalg.cholesky() method.
print("\nCholesky decomposition in Linear Algebra...\n",np.linalg.cholesky(arr))

출력

Our Array...
[[ 1.+0.j -0.-2.j]
[ 0.+2.j 5.+0.j]]

Dimensions of our Array...
2

Datatype of our Array object...
complex128

Shape of our Array object...
(2, 2)

Cholesky decomposition in Linear Algebra...
[[1.+0.j 0.+0.j]
[0.+2.j 1.+0.j]]