ในการส่งคืนเมทริกซ์ที่แสดงร่วมที่ปรับขนาดของอาร์เรย์ 1-D ของสัมประสิทธิ์พหุนาม Legendre ให้ใช้เมธอด thelegendre.legcompanion() ใน Python Numpy เมทริกซ์ร่วมตามปกติของ Legendrepolynomials มีความสมมาตรอยู่แล้วเมื่อ c เป็นพหุนามฐาน Laguerre ดังนั้นจึงไม่มีการใช้มาตราส่วน
ส่งกลับเมทริกซ์ Companion ที่ปรับขนาดของมิติข้อมูล (deg, deg) พารามิเตอร์ c คืออาร์เรย์ 1-D ของค่าสัมประสิทธิ์อนุกรมตำนานที่เรียงจากระดับต่ำไปสูง
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np from numpy.polynomial import legendre as L
สร้างอาร์เรย์ 1D ของสัมประสิทธิ์ -
c = np.array([1, 2, 3, 4, 5])
แสดงอาร์เรย์ -
print("Our Array...\n",c) ตรวจสอบขนาด -
print("\nDimensions of our Array...\n",c.ndim) รับประเภทข้อมูล -
print("\nDatatype of our Array object...\n",c.dtype) รับรูปร่าง -
print("\nShape of our Array object...\n",c.shape) ในการส่งคืนเมทริกซ์ที่แสดงร่วมที่ปรับขนาดของอาร์เรย์ 1-D ของสัมประสิทธิ์พหุนาม Legendre ให้ใช้เมธอด thelegendre.legcompanion() ใน Python Numpy เมทริกซ์ที่แสดงร่วมตามปกติของ Legendrepolynomials มีความสมมาตรอยู่แล้วเมื่อ c เป็นพหุนามฐาน Laguerre ดังนั้นจึงไม่มีการใช้มาตราส่วน -
print("\nResult...\n",L.legcompanion(c)) ตัวอย่าง
import numpy as np
from numpy.polynomial import legendre as L
# Create a 1D array of coefficients
c = np.array([1, 2, 3, 4, 5])
# Display the array
print("Our Array...\n",c)
# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)
# Get the Shape
print("\nShape of our Array object...\n",c.shape)
# To return the scaled companion matrix of a 1-D array of Legendre polynomial coefficients, use the legendre.legcompanion() method in Python Numpy
print("\nResult...\n",L.legcompanion(c)) ผลลัพธ์
Our Array... [1 2 3 4 5] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (5,) Result... [[ 0. 0.57735027 0. -0.30237158] [ 0.57735027 0. 0.51639778 -0.34914862] [ 0. 0.51639778 0. 0.10141851] [ 0. 0. 0.50709255 -0.45714286]]