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

Phân biệt chuỗi Legendre với hệ số đa chiều qua trục cụ thể trong Python

Để phân biệt chuỗi Legendre, hãy sử dụng phương thức polynomial.laguerre.legder () trong Python. Trả về hệ số chuỗi Legendre c phân biệt m lần dọc theo trục. Ở mỗi lần lặp, kết quả được nhân với scl. Tham số thứ nhất, c là một mảng các hệ số chuỗi Legendre. Nếu c là đa chiều, trục khác nhau tương ứng với các biến khác nhau với mức độ trong mỗi trục được giới hạn bởi chỉ số tương ứng.

Tham số thứ 2, m là số đạo hàm được lấy, phải không âm. (Mặc định:1). Tham số thứ 3, scl là một đại lượng vô hướng. Mỗi sự khác biệt được nhân với scl. Kết quả cuối cùng là phép nhân theo scl ** m. Điều này được sử dụng trong một biến thay đổi tuyến tính. (Mặc định:1). Tham số thứ 4, trục là anAxis mà đạo hàm được lấy. (Mặc định:0).

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 legendre as L

Tạo một mảng hệ số đa chiều -

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

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)

Để phân biệt chuỗi Legendre, hãy sử dụng phương thức polynomial.laguerre.legder () trong Python -

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))

Đầu ra

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.]]