Python NumPy에서 Hermite_e(확률론적 에르미트) 다항식의 Vandermonde 행렬을 생성하려면 hermite_e.hermevander() 함수를 사용합니다. 이 메서드는 의사 Vandermonde(pseudo-Vandermonde) 행렬을 반환하며, 반환되는 행렬의 형태는 x.shape + (deg + 1,)입니다. 여기서 마지막 인덱스는 해당 Hermite_e 다항식의 차수를 나타냅니다. 반환 행렬의 dtype은 변환된 x와 동일하게 유지됩니다.
Hermite_e 다항식은 통계학과 물리학 분야에서 널리 사용되는 직교 다항식으로, 이러한 다항식 기반으로 데이터를 피팅(fitting)할 때 Vandermonde 행렬이 핵심적인 역할을 합니다.
매개변수 x는 점들의 배열을 의미합니다. 요소 중 하나라도 복소수가 포함되어 있으면 dtype은 float64 또는 complex128로 변환되며, x가 스칼라 값인 경우 자동으로 1차원 배열로 변환됩니다. 매개변수 deg는 생성될 결과 행렬의 차수를 지정합니다.
단계별 구현 방법
먼저 필요한 라이브러리를 임포트합니다.
import numpy as np from numpy.polynomial import hermite_e as H
Vandermonde 행렬을 계산할 배열을 생성합니다.
x = np.array([0, 1, -1, 2])
생성한 배열을 화면에 출력합니다.
print("Our Array...\n",x)배열의 차원을 확인합니다.
print("\nDimensions of our Array...\n",x.ndim)배열 객체의 데이터 타입(dtype)을 확인합니다.
print("\nDatatype of our Array object...\n",x.dtype)배열 객체의 형태(shape)를 확인합니다.
print("\nShape of our Array object...\n",x.shape)Hermite_e 다항식의 Vandermonde 행렬을 생성하기 위해 Python NumPy의 hermite_e.hermevander() 함수를 호출합니다. 여기서는 차수(deg)를 2로 지정했습니다.
print("\nResult...\n",H.hermevander(x, 2))전체 예제 코드
import numpy as np
from numpy.polynomial import hermite_e as H
# 배열 생성
x = np.array([0, 1, -1, 2])
# 배열 출력
print("Our Array...\n",x)
# 차원 확인
print("\nDimensions of our Array...\n",x.ndim)
# 데이터 타입 확인
print("\nDatatype of our Array object...\n",x.dtype)
# 형태 확인
print("\nShape of our Array object...\n",x.shape)
# hermite_e.hermevander()를 사용하여 Hermite_e 다항식의 Vandermonde 행렬 생성
print("\nResult...\n",H.hermevander(x, 2))실행 결과
Our Array...
[ 0 1 -1 2]
Dimensions of our Array...
1
Datatype of our Array object...
int64
Shape of our Array object...
(4,)
Result...
[[ 1. 0. -1.]
[ 1. 1. 0.]
[ 1. -1. 0.]
[ 1. 2. 3.]]실행 결과를 보면 입력 배열 x의 각 원소에 대해 0차부터 2차까지의 Hermite_e 다항식 값이 열 방향으로 계산되어 4×3 크기의 Vandermonde 행렬이 생성된 것을 확인할 수 있습니다. 각 행은 입력 점 하나에 대응되며, 마지막 축의 크기가 deg + 1 = 3인 것도 앞서 설명한 규칙과 일치합니다.