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

การประเมินค่าอนุกรม Laguerre ที่จุดข้อมูลแบบหลายมิติใน Python


บทนำ

ในการประเมินค่าอนุกรม Laguerre ที่จุดข้อมูล x แบบหลายมิติ สามารถใช้เมธอด polynomial.laguerre.lagval() จาก NumPy พารามิเตอร์แรกคือ x หาก x เป็นลิสต์หรือทูเพิล จะถูกแปลงเป็น ndarray มิฉะนั้นจะคงค่าเดิมและถือเป็นสเกลาร์ พารามิเตอร์ที่สอง C คืออาเรย์ของสัมประสิทธิ์ที่เรียงลำดับโดยสัมประสิทธิ์ของพจน์ที่มีองศา n จะอยู่ใน c[n] พารามิเตอร์ที่สาม tensor หากเป็น True รูปร่างของอาเรย์สัมประสิทธิ์จะถูกขยายด้วยหนึ่งที่ด้านขวา สำหรับแต่ละมิติของ x ค่าเริ่มต้นคือ True

ขั้นตอนการทำงาน

1. นำเข้าไลบรารี

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

2. สร้างอาเรย์สัมประสิทธิ์

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

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)

4. กำหนดค่า x เป็นอาเรย์ 2 มิติ

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

5. ประเมินค่าอนุกรม Laguerre

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 เป็นอาเรย์ 2 มิติ
x = np.array([[1, 2], [3, 4]])

# ประเมินค่าอนุกรม Laguerre
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...   [[-0.5 -4. ]
             [-4.5 -2. ]]