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

การประเมินค่าอนุกรม Laguerre โดยกระจายจุด x ไปตามคอลัมน์สัมประสิทธิ์ใน Python


บทนำ

ในการประเมินค่าอนุกรม Laguerre ที่จุด x โดยการกระจาย (broadcast) จุด x ไปตามคอลัมน์ของสัมประสิทธิ์ สามารถใช้เมธอด polynomial.laguerre.lagval() พร้อมตั้งค่า tensor=False พารามิเตอร์ tensor ควบคุมการขยายรูปร่างของอาเรย์สัมประสิทธิ์ หากเป็น False x จะถูกกระจายไปตามคอลัมน์ของ c ซึ่งมีประโยชน์เมื่อ c เป็นหลายมิติ

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

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

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

2. สร้างอาเรย์สัมประสิทธิ์แบบหลายมิติ

c = np.arange(4).reshape(2, 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)

4. ประเมินค่าด้วย tensor=False

print("\nResult...\n", L.lagval([1, 2], c, tensor=False))

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

import numpy as np
from numpy.polynomial import laguerre 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)

# ประเมินค่าด้วย tensor=False
print("\nResult...\n", L.lagval([1, 2], c, tensor=False))

ผลลัพธ์ที่คาดหวัง

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...   [ 0. -2.]