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

ประเมินค่าอนุกรมลากูร์ร์ที่ทูเพิลจุด x ใน Python

คล้ายกับกรณีลิสต์ เมธอด lagval() ยอมรับ x เป็นทูเพิลเช่นกัน ทำงานเหมือนกันทุกประการ เพียงแต่ประเภทข้อมูลอินพุตต่างกัน

ขั้นตอน

นำเข้าไลบรารีและสร้างอาร์เรย์係ณ:

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

c = np.array([1, 2, 3])

กำหนด x เป็นทูเพิล:

x = (5, 10, 15)

ประเมินค่า:

print("\nResult...\n", L.lagval(x, c))

ตัวอย่างโค้ดสมบูรณ์

import numpy as np
from numpy.polynomial import laguerre 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 = (5, 10, 15)
print("\nResult...\n", L.lagval(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...   [ 3.5 76. 223.5]