ในการส่งคืนการสลายตัวของ Cholesky ให้ใช้เมธอด numpy.linalg.cholesky() ส่งกลับการสลายตัวของ Cholesky, L * L.H, ของเมทริกซ์สี่เหลี่ยมจัตุรัส a โดยที่ L คือรูปสามเหลี่ยมล่างและ .H คือโอเปอเรเตอร์ทรานสโพสคอนจูเกต ต้องเป็น Hermitian และแน่นอนในเชิงบวก ไม่มีการตรวจสอบเพื่อตรวจสอบว่า a เป็น Hermitian หรือไม่ นอกจากนี้ ใช้เฉพาะองค์ประกอบรูปสามเหลี่ยมล่างและเส้นทแยงมุมของ a มีเพียง L เท่านั้นที่ส่งคืน
จากนั้นพารามิเตอร์ a คือ Hermitian (สมมาตรหากองค์ประกอบทั้งหมดเป็นจริง) เมทริกซ์อินพุตที่มีค่าบวกแน่นอน วิธีการส่งคืนปัจจัย Cholesky บนหรือสามเหลี่ยมล่างของ a ส่งกลับวัตถุเมทริกซ์ถ้าเป็นวัตถุเมทริกซ์
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np
การสร้างอาร์เรย์ numpy 2 มิติโดยใช้เมธอด numpy.array() -
arr = np.array([[1,-2j],[2j,5]])
แสดงอาร์เรย์ -
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)
ในการส่งคืนการสลายตัวของ Cholesky ให้ใช้วิธีการ numpy.linalg.cholesky() -
print("\nCholesky decomposition in Linear Algebra...\n",np.linalg.cholesky(arr)) ตัวอย่าง
import numpy as np
# Creating a 2D numpy array using the numpy.array() method
arr = np.array([[1,-2j],[2j,5]])
# 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 return the Cholesky decomposition, use the numpy.linalg.cholesky() method.
print("\nCholesky decomposition in Linear Algebra...\n",np.linalg.cholesky(arr)) ผลลัพธ์
Our Array... [[ 1.+0.j -0.-2.j] [ 0.+2.j 5.+0.j]] Dimensions of our Array... 2 Datatype of our Array object... complex128 Shape of our Array object... (2, 2) Cholesky decomposition in Linear Algebra... [[1.+0.j 0.+0.j] [0.+2.j 1.+0.j]]