ในการส่งคืนเมทริกซ์ที่แสดงร่วมของอาร์เรย์ 1-D ของสัมประสิทธิ์พหุนาม ให้ส่งคืนเมธอด polynomial.polycompanion() ใน Python Numpy เมทริกซ์ที่แสดงร่วมสำหรับอนุกรมกำลังไม่สามารถทำให้สมมาตรได้โดยการปรับขนาดพื้นฐาน ดังนั้นฟังก์ชันนี้จึงแตกต่างจากฟังก์ชันสำหรับพหุนามตั้งฉาก เมธอดส่งคืนเมทริกซ์ที่แสดงร่วมของมิติข้อมูล (deg, deg) พารามิเตอร์ c คืออาร์เรย์ 1-D ของสัมประสิทธิ์พหุนามเรียงจากระดับต่ำไปสูง
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np from numpy.polynomial.polynomial import polycompanion
สร้างอาร์เรย์ 1D ของสัมประสิทธิ์ -
c = np.array([1, 2, 3])
แสดงอาร์เรย์ -
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 ของสัมประสิทธิ์พหุนาม ให้ส่งคืนเมธอด polynomial.polycompanion() -
print("\nResult...\n",polycompanion(c)) ตัวอย่าง
import numpy as np
from numpy.polynomial.polynomial import polycompanion
# Create a 1D array of coefficients
c = np.array([1, 2, 3])
# 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 companion matrix of a 1-D array of polynomial coefficients, return the polynomial.polycompanion() method in Python Numpy
print("\nResult...\n",polycompanion(c)) ผลลัพธ์
Our Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [[ 0. -0.33333333] [ 1. -0.66666667]]