ในการคำนวณหมายเลขเงื่อนไขของเมทริกซ์ในพีชคณิตเชิงเส้น ให้ใช้เมธอด numpy.linalg.cond() ใน Python วิธีนี้สามารถส่งคืนหมายเลขเงื่อนไขโดยใช้หนึ่งในเจ็ดบรรทัดฐานที่แตกต่างกัน ขึ้นอยู่กับค่าของ p
ส่งกลับหมายเลขเงื่อนไขของเมทริกซ์ อาจจะไม่มีที่สิ้นสุด จำนวนเงื่อนไขของ x ถูกกำหนดให้เป็นบรรทัดฐานของ x คูณบรรทัดฐานของค่าผกผันของ x; บรรทัดฐานสามารถเป็นบรรทัดฐาน L2 ปกติหรือบรรทัดฐานของเมทริกซ์อื่นจำนวนหนึ่ง พารามิเตอร์ที่ 1 คือ x เมทริกซ์ที่มีหมายเลขเงื่อนไข พารามิเตอร์ตัวที่ 2 คือ p ลำดับของบรรทัดฐานที่ใช้ในการคำนวณหมายเลขเงื่อนไข
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np from numpy import linalg as LA
สร้างอาร์เรย์ -
arr = np.array([[ 1, 1, 0], [1, 0, 1], [1, 0, 0]])
แสดงอาร์เรย์ -
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.cond() ใน Python -
print("\nResult...\n",LA.cond(arr)) ตัวอย่าง
import numpy as np
from numpy import linalg as LA
# Create an array
arr = np.array([[ 1, 1, 0],
[1, 0, 1],
[1, 0, 0]])
# 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 condition number of a matrix in linear algebra, use the numpy.linalg.cond() method in Python
print("\nResult...\n",LA.cond(arr)) ผลลัพธ์
Our Array... [[1 1 0] [1 0 1] [1 0 0]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (3, 3) Result... 3.7320508075688776