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

บวกอนุกรมลากูร์ร์สองอนุกรมใน Python

เมธอด polynomial.laguerre.lagadd() บวกอนุกรมลากูร์ร์สองอนุกรม คืนค่าอาร์เรย์แทนอนุกรมของผลรวม

พารามิเตอร์ c1 และ c2 เป็นอาร์เรย์ 1 มิติของ係ณเรียงจากดีกรีต่ำไปสูง

ขั้นตอน

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 (sum)....\n", L.lagadd(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 (sum)....\n", L.lagadd(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 (sum).... [4. 4. 4.]