Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

สร้างชุด Hermite_e จากรากที่กำหนดใน Python


เพื่อสร้างชุด Hermite_e จากรากที่กำหนด ให้ใช้เมธอด hermite_e.hermefromroots() ใน Python Numpy เมธอดคืนค่าอาร์เรย์ 1-D ของ係 หากรากทั้งหมดเป็นจริง out จะเป็น real array หากบางรากเป็น complex out จะเป็น complex แม้係ทั้งหมดในผลลัพธ์จะเป็นจริง พารามิเตอร์ roots คือลำดับที่มีราก

ขั้นตอน

ก่อนอื่น import ไลบรารีที่จำเป็น:

from numpy.polynomial import hermite_e as H

สร้างชุด Hermite_e จากราก:

print("Result...\n", H.hermefromroots((-1, 0, 1)))

ดึง datatype:

print("\nType...\n", H.hermefromroots((-1, 0, 1)).dtype)

ดึง shape:

print("\nShape...\n", H.hermefromroots((-1, 0, 1)).shape)

ตัวอย่าง

from numpy.polynomial import hermite_e as H

# To generate a Hermite_e series with given roots
print("Result...\n", H.hermefromroots((-1, 0, 1)))

# Get the datatype
print("\nType...\n", H.hermefromroots((-1, 0, 1)).dtype)

# Get the shape
print("\nShape...\n", H.hermefromroots((-1, 0, 1)).shape)

ผลลัพธ์

Result...   [0. 2. 0. 1.]
Type... float64
Shape... (4,)