ในการคำนวณค่าผกผัน (การคูณ) ของเมทริกซ์ ให้ใช้เมธอด numpy.linalg.inv() ใน Python รับเมทริกซ์สี่เหลี่ยม a ส่งคืนเมทริกซ์ ainv จุดที่น่าพอใจ (a, ainv) =dot (ainv, a) =ตา (a.shape[0]) วิธีการส่งคืน (การคูณ) ผกผันของเมทริกซ์ a พารามิเตอร์ที่ 1 a คือเมทริกซ์ที่จะกลับด้าน
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น-
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) ในการคำนวณค่าผกผัน (การคูณ) ของเมทริกซ์ ให้ใช้เมธอด numpy.linalg.inv() ใน Python -
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]]