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

Nhân một chuỗi Hermite với một biến độc lập trong Python

Để nhân chuỗi Hermite với x, trong đó x là biến độc lập, hãy sử dụng phương thức thepolynomial.hermite.hermmulx () trong Python Numpy. Phương thức trả về một mảng đại diện cho kết quả của phép nhân. Tham số, c là mảng 1-D gồm các hệ số chuỗi Hermite được sắp xếp từ thấp đến cao.

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 hermite as H

Tạo một mảng -

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

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)

Để nhân chuỗi Hermite với x, trong đó x là biến độc lập, hãy sử dụng phương thức thepolynomial.hermite.hermmulx () -

print("\nResult....\n",H.hermmulx(c))

Ví dụ

import numpy as np
from numpy.polynomial import hermite as H

# Create an array
c = np.array([1, 2, 3])

# 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 multiply the Hermite series by x, where x is the independent variable, use the polynomial.hermite.hermmulx() method in Python Numpy
print("\nResult....\n",H.hermmulx(c))

Đầu ra

Our Array...
   [1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result....
   [2. 6.5 1. 1.5]