Computer >> 컴퓨터 >  >> 프로그래밍 >> Python

Python NumPy의 herme2poly() 메서드로 Hermite_e 급수를 다항식으로 변환하기

Python NumPy에서 hermite_e.herme2poly() 메서드를 사용하면 Hermite_e 급수를 다항식으로 손쉽게 변환할 수 있습니다. 이 메서드는 낮은 차수부터 높은 차수 순으로 정렬된 Hermite_e 급수의 계수 배열을, '표준(standard)' 기저에 해당하는 다항식의 계수 배열로 변환해 줍니다.

반환 결과는 1차원 배열이며, 표준 기저에 대한 다항식 계수가 가장 낮은 차수 항부터 가장 높은 차수 항까지 순서대로 포함됩니다. 매개변수 c는 Hermite 급수의 계수를 담고 있는 1차원 배열로, 역시 낮은 차수부터 높은 차수 순으로 정렬되어 있어야 합니다.

변환 단계

먼저 필요한 라이브러리를 임포트합니다.

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

numpy.array() 메서드를 사용하여 배열을 생성합니다.

c = np.array([1, 2, 3, 4, 5])

생성된 배열을 화면에 출력합니다.

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

배열의 차원을 확인합니다.

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

배열 객체의 데이터 타입을 확인합니다.

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

배열 객체의 형태(shape)를 확인합니다.

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

이제 hermite_e.herme2poly() 메서드를 사용하여 Hermite_e 급수를 다항식으로 변환합니다.

print("\nResult (hermite_e to polynomial)...\n",H.herme2poly(c))

전체 예제 코드

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

# numpy.array() 메서드로 배열 생성
c = np.array([1, 2, 3, 4, 5])

# 배열 출력
print("Our Array...\n",c)

# 차원 확인
print("\nDimensions of our Array...\n",c.ndim)

# 데이터 타입 확인
print("\nDatatype of our Array object...\n",c.dtype)

# 형태(shape) 확인
print("\nShape of our Array object...\n",c.shape)

# hermite_e.herme2poly() 메서드로 Hermite_e 급수를 다항식으로 변환
print("\nResult (hermite_e to polynomial)...\n",H.herme2poly(c))

실행 결과

Our Array...
    [1 2 3 4 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result (hermite_e to polynomial)...
    [ 13. -10. -27. 4. 5.]

위 실행 결과에서 볼 수 있듯이, 입력된 Hermite_e 급수 계수 [1, 2, 3, 4, 5]는 표준 다항식 기저의 계수 [13, -10, -27, 4, 5]로 변환됩니다. 즉, 원래의 Hermite_e 급수와 동일한 값을 갖는 일반 다항식이 얻어지는 것입니다.