Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Đánh giá chuỗi Hermite_e 2-D trên tích Descartes của x và y trong Python


Để đánh giá chuỗi Hermite_e 2-D trên tích Descartes của x và y, dùng phương thức hermite.hermegrid2d(x, y, c) trong Python. Phương thức trả về giá trị của đa thức 2 chiều tại các điểm trong tích Descartes của x và y.

Tham số là x, y. Đa thức 2 chiều được đánh giá tại các điểm trong tích Descartes của x và y. Nếu x hoặc y là list hoặc tuple, nó đầu tiên chuyển thành ndarray, ngược lại giữ nguyên và, nếu không phải ndarray, coi như scalar.

Tham số c là mảng hệ số có thứ tự sao cho hệ số cho terms degree i,j chứa trong c[i,j]. Nếu c có dimension lớn hơn 2, các index còn lại enumerate multiple sets của hệ số.

Nếu c có ít hơn 2 dimension, 1 được ngầm thêm vào shape để làm nó 2-D. Shape của kết quả sẽ là c.shape[2:] + x.shape.

Các bước

Đầu tiên, import thư viện cần thiết:

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

Tạo mảng 2D hệ số:

c = np.arange(4).reshape(2,2)

Hiển thị mảng:

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

Kiểm tra Dimensions:

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

Lấy Datatype:

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

Lấy Shape:

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

Đánh giá chuỗi Hermite_e 2-D trên tích Descartes của x và y, dùng hermite.hermegrid2d(x, y, c):

print("\nResult...\n", H.hermegrid2d([1,2],[1,2], c))

Ví dụ

import numpy as np
from numpy.polynomial import hermite_e as H
# Create a 2D array of coefficients
c = np.arange(4).reshape(2,2)
# 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 evaluate a 2-D Hermite_e series on the Cartesian product of x and y, use the hermite.hermegrid2d(x, y, c) method in Python
print("\nResult...\n", H.hermegrid2d([1,2],[1,2], c))

Kết quả

Our Array...   [[0 1]
   [2 3]]
Dimensions of our Array... 2
Datatype of our Array object... int64
Shape of our Array object... (2, 2)
Result...   [[ 6. 10.]
   [11. 18.]]