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

Đạo hàm chuỗi Legendre với hệ số đa chiều trên axis cụ thể trong Python


Để đạo hàm chuỗi Legendre, dùng phương thức polynomial.laguerre.legder() trong Python. Trả về hệ số chuỗi Legendre c đã đạo hàm m lần dọc theo axis. Tại mỗi lần lặp, kết quả nhân với scl.

Tham số 1, c là mảng hệ số chuỗi Legendre. Nếu c đa chiều, các trục khác nhau tương ứng biến khác với degree mỗi trục cho bởi index tương ứng. Tham số 2, m là số lần đạo hàm, phải non-negative (Default: 1). Tham số 3, scl là scalar. Mỗi đạo hàm nhân với scl. Kết quả cuối nhân với scl**m. Dùng cho linear change of variable (Default: 1). Tham số 4, axis là trục đạo hàm (Default: 0).

Các bước

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

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

Tạo mảng đa chiều 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)

Đạo hàm chuỗi Legendre, dùng polynomial.laguerre.legder():

print("\nResult...\n", L.legder(c, axis = 1))

Ví dụ

import numpy as np
from numpy.polynomial import legendre as L
# Create a multidimensional 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 differentiate a Legendre series, use the polynomial.laguerre.legder() method in Python
print("\nResult...\n", L.legder(c, axis = 1))

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...   [[1.]
   [3.]]