ในการคำนวณล็อกดีเทอร์มิแนนต์สำหรับสแต็กของเมทริกซ์ ให้ใช้เมธอด numpy.linalg.slogdet() ใน Python พารามิเตอร์ตัวที่ 1 s คืออาร์เรย์อินพุต ต้องเป็นอาร์เรย์ 2 มิติแบบสี่เหลี่ยม เมธอดที่มีเครื่องหมายจะคืนค่าตัวเลขที่แสดงเครื่องหมายของดีเทอร์มีแนนต์ สำหรับเมทริกซ์จริง นี่คือ 1, 0 หรือ -1 สำหรับเมทริกซ์เชิงซ้อน นี่คือจำนวนเชิงซ้อนที่มีค่าสัมบูรณ์ 1 หรืออย่างอื่น 0
เมธอดที่มี logdet ส่งคืนล็อกธรรมชาติของค่าสัมบูรณ์ของดีเทอร์มีแนนต์ หากดีเทอร์มีแนนต์เป็นศูนย์ เครื่องหมายจะเป็น 0 และ logdet จะเป็น -Inf ในทุกกรณี ดีเทอร์มีแนนต์เท่ากับเครื่องหมาย * np.exp(logdet)
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น-
import numpy as np
สร้างอาร์เรย์ -
arr = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ])
แสดงอาร์เรย์ -
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)) ในการคำนวณล็อกดีเทอร์มิแนนต์สำหรับสแต็กของเมทริกซ์ ให้ใช้เมธอด numpy.linalg.slogdet() หากดีเทอร์มีแนนต์เป็นศูนย์ เครื่องหมายจะเป็น 0 และ logdet จะเป็น -Inf ในทุกกรณี ดีเทอร์มีแนนต์เท่ากับเครื่องหมาย * 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]], [[1, 2], [2, 1]], [[1, 3], [3, 1]]])
# 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 log-determinants for a stack of matrices, 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]] [[1 2] [2 1]] [[1 3] [3 1]]] Dimensions of our Array... 3 Datatype of our Array object... int64 Shape of our Array object... (3, 2, 2) Determinant... [-2. -3. -8.] Result.... (array([-1., -1., -1.]), array([0.69314718, 1.09861229, 2.07944154]))