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

แปลงชุด Hermite_e เป็นพหุนามใน Python


เพื่อแปลงชุด Hermite_e เป็นพหุนาม ให้ใช้เมธอด hermite_e.herme2poly() ใน Python Numpy แปลงอาร์เรย์ที่แสดง係ของชุด Hermite_e เรียงจากอันดับต่ำสุดไปสูงสุด เป็นอาร์เรย์ของ係ของพหุนามที่เทียบเท่า (relative to "standard" basis) เรียงจากอันดับต่ำสุดไปสูงสุด เมธอดคืนค่าอาร์เรย์ 1-D ที่มี係ของพหุนามที่เทียบเท่า พารามิเตอร์ c คืออาร์เรย์ 1-D ที่มี係ของชุด Hermite เรียงจากอันดับต่ำสุดไปสูงสุด

ขั้นตอน

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

import numpy as np
from numpy.polynomial import hermite_e as H

สร้างอาร์เรย์ด้วย numpy.array():

c = np.array([1, 2, 3, 4, 5])

แสดงอาร์เรย์:

print("Our Array...\n", c)

ตรวจสอบมิติ:

print("\nDimensions of our Array...\n", c.ndim)

ดึง datatype:

print("\nDatatype of our Array object...\n", c.dtype)

ดึง shape:

print("\nShape of our Array object...\n", c.shape)

แปลงชุด Hermite_e เป็นพหุนามด้วย hermite_e.herme2poly():

print("\nResult (hermite_e to polynomial)...\n", H.herme2poly(c))

ตัวอย่าง

import numpy as np
from numpy.polynomial import hermite_e as H

# Create an array using the numpy.array() method
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 convert a Hermite_e series to a polynomial
print("\nResult (hermite_e to polynomial)...\n", H.herme2poly(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 (hermite_e to polynomial)...   [ 13. -10. -27. 4. 5.]