ในการสร้างชุด Hermite ที่มีรากที่ซับซ้อนที่กำหนด ให้ใช้เมธอด hermite.hermfromroots() ในPython Numpy วิธีการส่งกลับอาร์เรย์ 1-D ของสัมประสิทธิ์ ถ้ารากทั้งหมดเป็นของจริง ค่าที่ออกมาจะเป็นเรียลอาร์เรย์ ถ้ารากบางส่วนนั้นซับซ้อน ค่าที่ออกมาจะซับซ้อนแม้ว่าสัมประสิทธิ์ทั้งหมดในผลลัพธ์จะเป็นจำนวนจริงก็ตาม พารามิเตอร์รากคือลำดับที่มีราก
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
from numpy.polynomial import hermite as H
ในการสร้างชุด Hermite ที่มีรากที่ซับซ้อนให้ใช้วิธี hermite.hermfromroots() -
j = complex(0,1)
print("Result...\n",H.hermfromroots((-j, j))) รับประเภทข้อมูล -
print("\nType...\n",H.hermfromroots((-j, j)).dtype) รับรูปร่าง -
print("\nShape...\n",H.hermfromroots((-j, j)).shape) ตัวอย่าง
from numpy.polynomial import hermite as H
# To generate a Hermite series with given complex roots, use the hermite.hermfromroots() method in Python Numpy.
# The method returns a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.
# The parameter roots are the sequence containing the roots.
j = complex(0,1)
print("Result...\n",H.hermfromroots((-j, j)))
# Get the datatype
print("\nType...\n",H.hermfromroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",H.hermfromroots((-j, j)).shape) ผลลัพธ์
Result... [1.5 +0.j 0. +0.j 0.25+0.j] Type... complex128 Shape... (3,)