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