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

Python의 Legendre 다항식에서 작은 후행 계수 제거

<시간/>

Legendre 다항식에서 작은 후행 계수를 제거하려면 Python numpy에서 legendre.legtrim() 메서드를 사용하십시오. 이 메서드는 후행 0이 제거된 1차원 배열을 반환합니다. 결과 시리즈가 비어 있으면 단일 0을 포함하는 시리즈가 반환됩니다.

"작음"은 "절대값이 작음"을 의미하며 매개변수 tol에 의해 제어됩니다. "후행"은 예를 들어 [0, 1, 1, 0, 0]에서 가장 높은 차수 계수를 의미합니다(0 + x + x**2 + 0*x**3 + 0*x**4를 나타냄). 3차 및 4차 계수 모두 "트리밍"됩니다. 매개변수 c는 가장 낮은 순서에서 가장 높은 순서로 정렬된 계수의 1차원 배열입니다. 매개변수 tol은 tol보다 작거나 같은 절대값을 갖는 후행 요소가 제거됩니다.

단계

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

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

numpy.array() 메서드를 사용하여 배열을 만듭니다. 이것은 계수의 1차원 배열입니다 -

c = np.array([0,5,0, 0,9,0])

배열 표시 -

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

치수 확인 -

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

데이터 유형 가져오기 -

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

모양 가져오기 -

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

Legendre 다항식에서 작은 후행 계수를 제거하려면 Python numpy -

에서 legendre.legtrim() 메서드를 사용하십시오.
print("\nResult...\n",L.legtrim(c))

예시

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

# Create an array using the numpy.array() method
# This is the 1-d array of coefficients
c = np.array([0,5,0, 0,9,0])

# 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 remove small trailing coefficients from Legendre polynomial, use the legendre.legtrim() method in Python numpy
print("\nResult...\n",L.legtrim(c))

출력

Our Array...
   [0 5 0 0 9 0]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
   [0. 5. 0. 0. 9.]