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

Tạo một chuỗi Hermite với các gốc phức đã cho bằng Python

Để tạo một chuỗi Hermite với các gốc phức đã cho, hãy sử dụng phương thức hermite.hermfromaries () trongPython Numpy. Phương thức trả về mảng hệ số 1-D. Nếu tất cả các gốc là thực thì out là một mảng thực, nếu một số gốc là phức, thì out là phức ngay cả khi tất cả các hệ số trong kết quả là thực. Các gốc tham số là trình tự chứa các gốc.

Các bước

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

from numpy.polynomial import hermite as H

Để tạo một chuỗi Hermite với các gốc phức đã cho, hãy sử dụng phương thức hermite.hermfromosystem () -

j = complex(0,1)
print("Result...\n",H.hermfromroots((-j, j)))

Nhận loại dữ liệu -

print("\nType...\n",H.hermfromroots((-j, j)).dtype)

Lấy hình dạng -

print("\nShape...\n",H.hermfromroots((-j, j)).shape)

Ví dụ

from numpy.polynomial import hermite as H

# To generate a Hermite series with given complex roots, use the hermite.hermfromroots() method in Python Numpy.
# The method returns a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.

# The parameter roots are the sequence containing the roots.
j = complex(0,1)
print("Result...\n",H.hermfromroots((-j, j)))

# Get the datatype
print("\nType...\n",H.hermfromroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n",H.hermfromroots((-j, j)).shape)

Đầu ra

Result...
   [1.5 +0.j 0. +0.j 0.25+0.j]

Type...
complex128

Shape...
(3,)