บทนำ
เมธอด polynomial.polyval2d() ใน NumPy ใช้ประเมินพหุนาม 2 มิติ ที่จุด (x, y) ส่งคืนค่าที่จุดที่สร้างจากคู่ค่าที่ตรงกันของ x และ y
พารามิเตอร์
- x, y: ต้องมีรูปร่างเดียวกัน แปลงจากลิสต์/ทูเพิลเป็น ndarray อัตโนมัติ
- c: อาร์เรย์สัมประสิทธิ์ c[i,j] สำหรับมัลติดีกรี i,j หาก c มีมิติ > 2 ดัชนีที่เหลือเป็นชุดสัมประสิทธิ์หลายชุด หาก c มีมิติ < 2 จะเพิ่มมิติ 1 อัตโนมัติ
ตัวอย่างโค้ด
import numpy as np
from numpy.polynomial.polynomial import polyval2d
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", polyval2d([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. 18.]