บทนำ
ในการประเมินค่าอนุกรม Laguerre 2 มิติ บนผลคูณการ์ทีเซียนของ x และ y สามารถใช้เมธอด polynomial.laguerre.laggrid2d() จาก NumPy เมธอดนี้คืนค่าของอนุกรม Laguerre 2 มิติ ที่จุดในผลคูณการ์ทีเซียนของ x และ y
หาก c มีมิติน้อยกว่า 2 จะมีการต่อหนึ่งเข้าไปเพื่อทำให้เป็น 2 มิติ รูปร่างผลลัพธ์จะเป็น c.shape[2:] + x.shape + y.shape
ขั้นตอนการทำงาน
1. นำเข้าไลบรารี
import numpy as np from numpy.polynomial import laguerre as L
2. สร้างอาเรย์สัมประสิทธิ์ 3 มิติ
c = np.arange(24).reshape(2, 2, 6)
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. ประเมินค่าอนุกรม Laguerre 2 มิติ
print("\nResult...\n", L.laggrid2d([1, 2], [1, 2], c))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import laguerre as L
# สร้างอาเรย์สัมประสิทธิ์ 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)
# ประเมินค่าอนุกรม Laguerre 2 มิติ
print("\nResult...\n", L.laggrid2d([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... [[[ 0. -6.]
[-12. 0.]]
[[ 1. -6.]
[-12. 0.]]
[[ 2. -6.]
[-12. 0.]]
[[ 3. -6.]
[-12. 0.]]
[[ 4. -6.]
[-12. 0.]]
[[ 5. -6.]
[-12. 0.]]]