Computer >> Máy Tính >  >> Lập trình >> Python

Chuyển đổi chuỗi Laguerre thành đa thức trong Python

Để chuyển đổi một chuỗi Laguerre thành một đa thức, hãy sử dụng phương thức laguerre.lag2poly () trong Python Numpy. theo cơ sở "tiêu chuẩn") được sắp xếp từ mức độ thấp nhất đến mức độ cao nhất.

Phương thức trả về một mảng 1-D chứa các hệ số của đa thức tương đương được sắp xếp từ số hạng thứ tự thấp nhất đến cao nhất. Tham số c, là mảng 1-D chứa hệ số chuỗi Laguerre, được sắp xếp từ số hạng thứ tự thấp nhất đến cao nhất.

Các bước

Đầu tiên, hãy nhập thư viện được yêu cầu -

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

Tạo một mảng bằng phương thức numpy.array () -

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

Hiển thị mảng -

print("Our Array...\n",c)

Kiểm tra các thứ nguyên -

print("\nDimensions of our Array...\n",c.ndim)

Lấy Datatype -

print("\nDatatype of our Array object...\n",c.dtype)

Lấy hình dạng -

print("\nShape of our Array object...\n",c.shape)

Để chuyển đổi chuỗi Laguerre thành đa thức, hãy sử dụng phương thức laguerre.lag2poly () trong Python Numpy -

print("\nResult (laguerre to polynomial)...\n",L.lag2poly(c))

Ví dụ

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

# Create an array using the numpy.array() method
c = np.array([1, 2, 3, 4, 5])

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To convert a Laguerre series to a polynomial, use the laguerre.lag2poly() method in Python Numpy
print("\nResult (laguerre to polynomial)...\n",L.lag2poly(c))

Đầu ra

Our Array...
   [1 2 3 4 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(5,)

Result (laguerre to polynomial)...
   [ 15. -40. 22.5 -4. 0.20833333]