파이썬 NumPy에서 한 Hermite_e(에르미트E) 급수를 다른 급수에서 뺄 때는 numpy.polynomial.hermite_e 모듈의 hermesub() 메서드를 사용합니다. 이 메서드는 두 Hermite_e 급수의 차(c1 − c2)를 나타내는 배열을 반환합니다. 계수 시퀀스는 가장 낮은 차수 항부터 가장 높은 차수 항까지 순서대로 정렬되며, 예를 들어 [1, 2, 3]은 P_0 + 2·P_1 + 3·P_2라는 급수를 의미합니다. 매개변수 c1과 c2는 각각 낮은 차수에서 높은 차수 순으로 정렬된 Hermite_e 급수 계수의 1차원 배열입니다.
단계별 구현 방법
먼저 필요한 라이브러리를 가져옵니다.
import numpy as np from numpy.polynomial import hermite_e as H
Hermite_e 급수 계수를 담은 1차원 배열을 생성합니다.
c1 = np.array([1,2,3]) c2 = np.array([3,2,1])
생성한 계수 배열을 화면에 출력합니다.
print("Array1...\n",c1)
print("\nArray2...\n",c2)
배열의 데이터 타입(dtype)을 확인합니다.
print("\nArray1 datatype...\n",c1.dtype)
print("\nArray2 datatype...\n",c2.dtype)
두 배열의 차원(ndim)을 확인합니다.
print("\nDimensions of Array1...\n",c1.ndim)
print("\nDimensions of Array2...\n",c2.ndim)
두 배열의 형태(shape)를 확인합니다.
print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)
이제 hermesub() 메서드를 호출하여 두 Hermite_e 급수의 차를 계산합니다.
print("\nResult (difference)....\n",H.hermesub(c1, c2))
전체 예제 코드
import numpy as np
from numpy.polynomial import hermite_e as H
# Hermite_e 급수 계수로 구성된 1차원 배열 생성
c1 = np.array([1,2,3])
c2 = np.array([3,2,1])
# 계수 배열 출력
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)
# hermesub() 메서드로 두 Hermite_e 급수의 차 계산
print("\nResult (difference)....\n",H.hermesub(c1, c2))
실행 결과
Array1...
[1 2 3]
Array2...
[3 2 1]
Array1 datatype...
int64
Array2 datatype...
int64
Dimensions of Array1...
1
Dimensions of Array2...
1
Shape of Array1...
(3,)
Shape of Array2...
(3,)
Result (difference)....
[-2. 0. 2.]
위 실행 결과에서 볼 수 있듯이, hermesub() 메서드는 두 입력 배열의 계수를 항별로 빼서 새로운 Hermite_e 급수 계수 배열을 반환합니다. 결과 배열은 부동소수점(float) 타입으로 반환되며, 이를 활용하면 에르미트E 다항식 기반의 다양한 수치 계산을 손쉽게 처리할 수 있습니다.