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

ประเมินอนุกรม Hermite_e ที่อาร์เรย์จุดหลายมิติ ด้วย Python

บทนำ

เมธอด hermite.hermeval() ใน NumPy ใช้สำหรับประเมินอนุกรม Hermite_e ที่จุด x โดยรองรับทั้งค่าสเกลาร์และอาร์เรย์หลายมิติ ทำให้สามารถคำนวณค่าพหุนามได้อย่างยืดหยุ่น

พารามิเตอร์สำคัญ

x (จุดที่ต้องการประเมิน)

หาก x เป็นลิสต์หรือทูเพิล จะถูกแปลงเป็น ndarray มิฉะนั้นจะถือเป็นสเกลาร์ ค่าของ x หรือองค์ประกอบต้องรองรับการบวกและคูณกับตัวเองและกับองค์ประกอบของ c

C (สัมประสิทธิ์)

อาร์เรย์สัมประสิทธิ์ที่เรียงตามดีกรี n อยู่ใน c[n] หาก c เป็นมิติหลาย ดัชนีที่เหลือจะแทนพหุนามหลายพหุนาม ในกรณี 2 มิติ สัมประสิทธิ์จะถูกเก็บในคอลัมน์ของ c

tensor (ตัวเลือก)

ค่าเริ่มต้นเป็น True จะขยายรูปร่างอาร์เรย์สัมประสิทธิ์ด้วย 1 ด้านขวาสำหรับแต่ละมิติของ x ทำให้ทุกคอลัมน์ของ c ถูกประเมินสำหรับทุกองค์ประกอบของ x หากเป็น False จะใช้ broadcasting แทน

ขั้นตอนการใช้งาน

1. นำเข้าไลบรารี

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

2. สร้างอาร์เรย์สัมประสิทธิ์

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

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)

4. กำหนดจุด x เป็นอาร์เรย์ 2 มิติ และประเมิน

x = np.array([[1, 2], [3, 4]])
print("\nResult...\n", H.hermeval(x, c))

ตัวอย่างโค้ดสมบูรณ์

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

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)

x = np.array([[1, 2], [3, 4]])
print("\nResult...\n", H.hermeval(x, c))

ผลลัพธ์

Our Array... [1 2 3]
Dimensions of our Array... 1
Datatype of our Array object... int64
Shape of our Array object... (3,)
Result...
 [[ 3. 14.]
 [31. 54.]]