บทนำ
การประเมินอนุกรมเลจันเดอร์ 2 มิติ บน Cartesian product ของ x และ y ใช้เมธอด polynomial.legendre.leggrid2d() ใน NumPy เมธอดคืนค่าของอนุกรม Chebyshev 2 มิติ ที่จุดใน Cartesian product ของ x และ y หาก c มีมิติน้อยกว่า 2 จะเพิ่ม ones เข้าไปเพื่อทำให้เป็น 2-D รูปร่างผลลัพธ์จะเป็น c.shape[2:] + x.shape + y.shape
พารามิเตอร์
- x, y: อนุกรม 2 มิติประเมินที่จุดใน Cartesian product ของ x และ y หากเป็น list/tuple จะแปลงเป็น ndarray
- c: อาร์เรย์สัมประสิทธิ์ที่ c[i,j] มีสัมประสิทธิ์ของพจน์ multi-degree i,j หาก c มากกว่า 2 มิติ ดัชนีที่เหลือนับชุดสัมประสิทธิ์หลายชุด
ขั้นตอนการทำงาน
1. นำเข้าไลบรารี
import numpy as np from numpy.polynomial import legendre as L
2. สร้างอาร์เรย์สัมประสิทธิ์ 2D
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. ประเมินอนุกรม 2D บน Cartesian product
print("\nResult...\n", L.leggrid2d([1, 2], [1, 2], c))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import legendre as L
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)
print("\nResult...\n", L.leggrid2d([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... [[ 6. 10.] [11. 18.]]