บทนำ
เพื่อประเมินอนุกรมเฮอร์ไมท์ (Hermite series) 2 มิติ ที่จุด (x, y) เราสามารถใช้เมธอด hermite.hermval2d() ใน NumPy เมธอดนี้จะส่งคืนค่าของพหุนาม 2 มิติ ที่จุดที่สร้างจากคู่ของค่าที่สอดคล้องกันจาก x และ y
พารามิเตอร์
- x, y: อนุกรม 2 มิติจะถูกประเมินที่จุด (x, y) โดยที่ x และ y ต้องมีรูปทรงเหมือนกัน หาก x หรือ y เป็นลิสต์หรือทูเพิล จะถูกแปลงเป็น ndarray ก่อน มิฉะนั้นจะคงค่าเดิม และหากไม่ใช่ ndarray จะถูกถือว่าเป็นสเกลาร์ (scalar)
- c: อาร์เรย์ของสัมประสิทธิ์ ที่จัดเรียงโดยสัมประสิทธิ์ของพจน์ที่มีมัลติดีกรี (multidegree) i, j จะอยู่ใน
c[i,j]หากcมีมิติมากกว่า 2 ดัชนีที่เหลือจะนับชุดของสัมประสิทธิ์หลายชุด
ขั้นตอนการทำงาน
1. นำเข้าไลบรารีที่จำเป็น
import numpy as np
from numpy.polynomial import hermite as H
2. สร้างอาร์เรย์สัมประสิทธิ์ 3 มิติ
c = np.arange(24).reshape(2, 2, 6)
3. แสดงอาร์เรย์
print("Our Array...\n", c)
4. ตรวจสอบมิติ
print("\nDimensions of our Array...\n", c.ndim)
5. ตรวจสอบชนิดข้อมูล
print("\nDatatype of our Array object...\n", c.dtype)
6. ตรวจสอบรูปทรง
print("\nShape of our Array object...\n", c.shape)
7. ประเมินอนุกรมเฮอร์ไมท์ 2 มิติ ที่จุด (x, y)
print("\nResult...\n", H.hermval2d([1, 2], [1, 2], c))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import hermite as H
# สร้างอาร์เรย์สัมประสิทธิ์ 3 มิติ
c = np.arange(24).reshape(2, 2, 6)
# แสดงอาร์เรย์
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)
# ประเมินอนุกรมเฮอร์ไมท์ 2 มิติ ที่จุด (x, y)
print("\nResult...\n", H.hermval2d([1, 2], [1, 2], c))
ผลลัพธ์ที่คาดหวัง
Our Array...
[[[ 0 1 2 3 4 5]
[ 6 7 8 9 10 11]]
[[12 13 14 15 16 17]
[18 19 20 21 22 23]]]
Dimensions of our Array...
3
Datatype of our Array object...
int64
Shape of our Array object...
(2, 2, 6)
Result...
[[108. 360.]
[117. 385.]
[126. 410.]
[135. 435.]
[144. 460.]
[153. 485.]]