บทนำ
การสร้างเมทริกซ์ Vandermonde แบบปลอมของพหุนามเลจันเดอร์ ใช้เมธอด polynomial.legvander() ใน NumPy คืนค่าเมทริกซ์ Vandermonde แบบปลอม รูปร่าง: x.shape + (deg + 1,) ดัชนีสุดท้ายคือดีกรีของพหุนามเลจันเดอร์ dtype เหมือน x ที่แปลงแล้ว
พารามิเตอร์
- x: อาร์เรย์จุด dtype แปลงเป็น float64 หรือ complex128 สเกลาร์แปลงเป็น 1-D array
- deg: ดีกรีของเมทริกซ์ที่ได้
ขั้นตอนการทำงาน
1. นำเข้าไลบรารี
import numpy as np from numpy.polynomial import legendre as L
2. สร้างอาร์เรย์
x = np.array([0, 1, -1, 2])
3. แสดงอาร์เรย์
print("Our Array...\n", x)
4. ตรวจสอบมิติ
print("\nDimensions of our Array...\n", x.ndim)
5. ตรวจสอบชนิดข้อมูล
print("\nDatatype of our Array object...\n", x.dtype)
6. ตรวจสอบรูปร่าง
print("\nShape of our Array object...\n", x.shape)
7. สร้างเมทริกซ์ Vandermonde
print("\nResult...\n", L.legvander(x, 2))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import legendre as L
x = np.array([0, 1, -1, 2])
print("Our Array...\n", x)
print("\nDimensions of our Array...\n", x.ndim)
print("\nDatatype of our Array object...\n", x.dtype)
print("\nShape of our Array object...\n", x.shape)
print("\nResult...\n", L.legvander(x, 2))
ผลลัพธ์ที่คาดหวัง
Our Array... [ 0 1 -1 2] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (4,) Result... [[ 1. 0. -0.5] [ 1. 1. 1. ] [ 1. -1. 1. ] [ 1. 2. 5.5]]