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