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

การคูณอนุกรม Laguerre กับอีกอนุกรมหนึ่งใน Python


บทนำ

ในการคูณอนุกรม Laguerre กับอีกอนุกรมหนึ่ง สามารถใช้เมธอด polynomial.laguerre.lagmul() จาก NumPy เมธอดนี้คืนค่าการคูณของอนุกรม Laguerre สองชุด c1 * c2

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

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

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

2. สร้างอาเรย์สัมประสิทธิ์ 1 มิติ 2 ชุด

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

3. แสดงอาเรย์และตรวจสอบคุณสมบัติ

print("Array1...\n", c1)
print("\nArray2...\n", c2)
print("\nArray1 datatype...\n", c1.dtype)
print("\nArray2 datatype...\n", c2.dtype)
print("\nDimensions of Array1...\n", c1.ndim)
print("\nDimensions of Array2...\n", c2.ndim)
print("\nShape of Array1...\n", c1.shape)
print("\nShape of Array2...\n", c2.shape)

4. คูณอนุกรม

print("\nResult (multiply)....\n", L.lagmul(c1, c2))

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

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

# สร้างอาเรย์สัมประสิทธิ์
c1 = np.array([1, 2, 3])
c2 = np.array([3, 2, 1])

# แสดงอาเรย์
print("Array1...\n", c1)
print("\nArray2...\n", c2)

# แสดงชนิดข้อมูล
print("\nArray1 datatype...\n", c1.dtype)
print("\nArray2 datatype...\n", c2.dtype)

# ตรวจสอบมิติ
print("\nDimensions of Array1...\n", c1.ndim)
print("\nDimensions of Array2...\n", c2.ndim)

# ตรวจสอบรูปร่าง
print("\nShape of Array1...\n", c1.shape)
print("\nShape of Array2...\n", c2.shape)

# คูณอนุกรม
print("\nResult (multiply)....\n", L.lagmul(c1, c2))

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

Array1...   [1 2 3]
Array2...   [3 2 1]
Array1 datatype... int64
Array2 datatype... int64
Dimensions of Array1... 1
Dimensions of Array2... 1
Shape of Array1... (3,)
Shape of Array2... (3,)
Result (multiply)....   [ 10. 4. 16. -12. 18.]