배열 행렬식의 부호와 자연 로그를 계산하려면 Python에서 numpy.linalg.slogdet() 메서드를 사용합니다. 첫 번째 매개변수인 s는 입력 배열이며 square2-D 배열이어야 합니다.
이 메서드는 부호가 있는 행렬식의 부호를 나타내는 숫자를 반환합니다. 실수 행렬의 경우 1, 0 또는 -1입니다. 복소수 행렬의 경우 이것은 절대값이 1 또는 0인 복소수입니다. logdet을 사용하는 이 메서드는 행렬식의 절대값에 대한 자연 로그를 반환합니다. 행렬식이 0이면 부호는 0이 되고 logdet는 -Inf가 됩니다. 모든 경우에 행렬식은 기호 * np.exp(logdet)와 같습니다.
단계
먼저 필요한 라이브러리를 가져옵니다 -
import numpy as np
배열 생성 -
arr = np.array([[ 1, 2], [ 3, 4]])
배열 표시 -
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) 선형 대수학에서 배열의 행렬식 -
print("\nDeterminant...\n",np.linalg.det(arr)) 배열 행렬식의 부호와 자연 로그를 계산하려면 Python에서 numpy.linalg.slogdet() 메서드를 사용합니다. 행렬식이 0이면 sign은 0이 되고 logdet는 -Inf가 됩니다. 모든 경우에 행렬식은 sign * np.exp(logdet) −
와 같습니다.(sign, logdet) = np.linalg.slogdet(arr)
print("\nResult....\n",(sign, logdet)) 예시
import numpy as np
# Create an array
arr = np.array([[ 1, 2],
[ 3, 4]])
# 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)
# The determinant of an array in linear algebra
print("\nDeterminant...\n",np.linalg.det(arr))
# To Compute the sign and natural logarithm of the determinant of an array, use the numpy.linalg.slogdet() method in Python
(sign, logdet) = np.linalg.slogdet(arr)
print("\nResult....\n",(sign, logdet)) 출력
Our Array... [[1 2] [3 4]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Determinant... -2.0000000000000004 Result.... (-1.0, 0.6931471805599455)