행렬의 (승법) 역행렬을 계산하려면 Python에서 numpy.linalg.inv() 메서드를 사용합니다. 정사각 행렬이 주어지면 ainv 행렬을 반환합니다. 만족하는 dot(a, ainv) =dot(ainv, a) =eye(a.shape[0]). 이 메서드는 행렬 a의 (승법) 역행렬을 반환합니다. 첫 번째 매개변수인 a는 반전할 Matrix입니다.
단계
먼저 필요한 라이브러리를 가져옵니다-
import numpy as np from numpy.linalg import inv
배열 생성 -
arr = np.array([[ 5, 10], [ 15, 20 ]])
배열 표시 -
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.inv() 메서드를 사용하십시오 -
print("\nResult...\n",np.linalg.inv(arr)) 예
import numpy as np
from numpy.linalg import inv
# Create an array
arr = np.array([[ 5, 10], [ 15, 20 ]])
# 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 compute the (multiplicative) inverse of a matrix, use the numpy.linalg.inv() method in Python.
print("\nResult...\n",np.linalg.inv(arr)) 출력
Our Array... [[ 5 10] [15 20]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [[-0.4 0.2] [ 0.3 -0.1]]