Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ประเมินอนุกรม Legendre ที่อาร์เรย์จุดหลายมิติใน Python

บทนำ

เมธอด legendre.legval() ประเมินอนุกรม Legendre ที่จุด x รองรับอาร์เรย์หลายมิติและพารามิเตอร์ tensor

ตัวอย่าง: x เป็นอาร์เรย์ 2 มิติ

import numpy as np
from numpy.polynomial import legendre as L

c = np.array([1, 2, 3])
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)

x = np.array([[1, 2], [3, 4]])
print("\nResult...\n", L.legval(x, c))

ผลลัพธ์

Our Array... [1 2 3]
Dimensions of our Array... 1
Datatype of our Array object... int64
Shape of our Array object... (3,)
Result... [[ 6.  21.5]
 [46.  79.5]]

อนุกรม P₀ + 2P₁ + 3P₂ ประเมินที่เมทริกซ์ 2x2 ให้ผลลัพธ์ 2x2