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

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


ในการแปลงอนุกรม Hermite เป็นพหุนาม ให้ใช้เมธอด hermite.herm2poly() ใน Python Numpy แปลงอาร์เรย์ที่แทนค่าสัมประสิทธิ์ของอนุกรม Hermite โดยเรียงลำดับจากระดับต่ำสุดไปสูงสุดเป็นอาร์เรย์ของสัมประสิทธิ์พหุนามเทียบเท่า (ญาติ ให้เป็นไปตาม "มาตรฐาน") โดยเรียงลำดับจากระดับต่ำสุดไปสูงสุด

วิธีการส่งกลับอาร์เรย์ 1-D ที่มีค่าสัมประสิทธิ์ของพหุนามเทียบเท่า (เทียบกับพื้นฐาน "มาตรฐาน") ที่เรียงลำดับจากระยะคำสั่งต่ำสุดไปสูงสุด พารามิเตอร์ c คืออาร์เรย์ 1-D ที่มีค่าสัมประสิทธิ์อนุกรม Hermite โดยเรียงลำดับจากระยะต่ำสุดไปสูงสุด

ขั้นตอน

ขั้นแรก นำเข้าไลบรารีที่จำเป็น -

import numpy as np
from numpy.polynomial import hermite 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)

รับประเภทข้อมูล -

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

รับรูปร่าง -

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

ในการแปลงอนุกรมเฮอร์ไมต์เป็นพหุนาม ให้ใช้เมธอด hermite.herm2poly() -

print("\nResult (hermite to polynomial)...\n",H.herm2poly(c))

ตัวอย่าง

import numpy as np
from numpy.polynomial import hermite 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 series to a polynomial, use the hermite.herm2poly() method in Python Numpy
print("\nResult (hermite to polynomial)...\n",H.herm2poly(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 to polynomial)...
[ 55. -44. -228. 32. 80.]