Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python에서 하나의 Legendre 시리즈를 다른 시리즈에 곱하기

<시간/>

하나의 Legendre 시리즈를 다른 것과 곱하려면 Python Numpy에서 polynomial.legendre.legmul() 메서드를 사용합니다. 이 메서드는 제품의 르장드르 계열을 나타내는 배열을 반환합니다. 두 개의 르장드르 계열 c1 * c2의 곱을 반환합니다. 인수는 가장 낮은 차수에서 가장 높은 순으로 정렬된 계수 시퀀스입니다. 즉, [1,2,3]은 시리즈 P_0 +2*P_1 + 3*P_2를 나타냅니다. 매개변수 c1 및 c2는 낮은 것에서 높은 순서로 정렬된 르장드르 급수 계수의 1차원 배열입니다.

단계

먼저 필요한 라이브러리를 가져옵니다 -

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

르장드르 급수 계수의 1차원 배열 생성 -

c1 = np.array([2,3,4])
c2 = np.array([4,3,2])

계수 배열 표시 -

print("Array1...\n",c1)
print("\nArray2...\n",c2)

데이터 유형 표시 -

print("\nArray1 datatype...\n",c1.dtype)
print("\nArray2 datatype...\n",c2.dtype)

두 어레이의 차원을 확인하십시오 -

print("\nDimensions of Array1...\n",c1.ndim)
print("\nDimensions of Array2...\n",c2.ndim)

두 배열의 모양을 확인하십시오 -

print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)

하나의 Legendre 시리즈를 다른 것과 곱하려면 Python Numpy에서 polynomial.legendre.legmul() 메소드를 사용하십시오 -

print("\nResult (product)....\n",L.legmul(c1, c2))

예시

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

# Create 1-D arrays of Legendre series coefficients
c1 = np.array([2,3,4])
c2 = np.array([4,3,2])

# Display the arrays of coefficients
print("Array1...\n",c1)
print("\nArray2...\n",c2)

# Display the datatype
print("\nArray1 datatype...\n",c1.dtype)
print("\nArray2 datatype...\n",c2.dtype)

# Check the Dimensions of both the arrays
print("\nDimensions of Array1...\n",c1.ndim)
print("\nDimensions of Array2...\n",c2.ndim)

# Check the Shape of both the arrays
print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)

# To multiply one Legendre series from another, use the polynomial.legendre.legmul() method in Python Numpy
# The method returns an array representing the Legendre series of their product.
print("\nResult (product)....\n",L.legmul(c1, c2))

출력

Array1...
   [2 3 4]

Array2...
   [4 3 2]

Array1 datatype...
int64

Array2 datatype...
int64

Dimensions of Array1...
1

Dimensions of Array2...
1

Shape of Array1...
(3,)

Shape of Array2...
(3,)

Result (product)....
   [12.6 25.2 28.28571429 10.8 4.11428571]