เมธอด polynomial.legendre.legval() ใช้ประเมินค่าอนุกรมเลจันดร์ (Legendre series) ที่จุด x พารามิเตอร์ tensor=True (ค่าเริ่มต้น) จะขยายรูปร่างอาร์เรย์係ณด้วย 1 ด้านขวาสำหรับแต่ละมิติของ x ทำให้ทุกคอลัมน์ของ係ณถูกประเมินสำหรับทุกสมาชิกของ x
ขั้นตอน
นำเข้าไลบรารี (สังเกต: ใช้ legendre ไม่ใช่ laguerre):
import numpy as np from numpy.polynomial import legendre as L
สร้างอาร์เรย์係ณหลายมิติ:
c = np.arange(4).reshape(2, 2)
แสดงข้อมูลและประเมินค่าด้วย tensor=True:
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.legval([1, 2], c, tensor=True))
ตัวอย่างโค้ดสมบูรณ์
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.legval([1, 2], c, tensor=True))
ผลลัพธ์
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... [[2. 4.] [4. 7.]]