Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

คำนวณดีเทอร์มีแนนต์ของอาร์เรย์ในพีชคณิตเชิงเส้นใน Python


ในการคำนวณดีเทอร์มีแนนต์ของอาร์เรย์ในพีชคณิตเชิงเส้น ให้ใช้ np.linalg.det() ใน Python Numpy พารามิเตอร์ที่ 1 a คืออาร์เรย์อินพุตสำหรับคำนวณดีเทอร์มีแนนต์ เมธอดจะคืนค่าดีเทอร์มีแนนต์

ขั้นตอน

ขั้นแรก นำเข้าไลบรารีที่จำเป็น -

import numpy as np

สร้างอาร์เรย์ -

arr = np.array([[ 5, 10], [12, 18]])

แสดงอาร์เรย์ -

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)

ในการคำนวณดีเทอร์มีแนนต์ของอาร์เรย์ในพีชคณิตเชิงเส้น ให้ใช้ np.linalg.det() ใน Python Numpy -

print("\nResult (determinant)...\n",np.linalg.det(arr))

ตัวอย่าง

import numpy as np

# Create an array
arr = np.array([[ 5, 10], [12, 18]])

# 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 determinant of an array in linear algebra, use the np.linalg.det() in Python Numpy.
print("\nResult (determinant)...\n",np.linalg.det(arr))

ผลลัพธ์

Our Array...
[[ 5 10]
[12 18]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

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

Result (determinant)...
-30.000000000000014