Python NumPy에서 Hermite 다항식의 Vandermonde 행렬을 생성하려면 chebyshev.hermvander() 함수를 사용합니다. 이 메서드는 의사(pseudo) Vandermonde 행렬을 반환하며, 반환되는 행렬의 형태는 x.shape + (deg + 1,)입니다. 여기서 마지막 인덱스는 해당 Hermite 다항식의 차수를 나타냅니다. 데이터 타입(dtype)은 변환된 x의 타입과 동일하게 유지됩니다.
주요 매개변수 설명
- x: 점들의 배열입니다. 요소 중 하나라도 복소수가 포함되어 있으면 dtype은 float64 또는 complex128로 변환됩니다. x가 스칼라 값이면 1차원 배열로 변환됩니다.
- deg: 결과 행렬의 차수입니다.
구현 단계
먼저 필요한 라이브러리를 가져옵니다.
import numpy as np
from numpy.polynomial import hermite as H
복소수 값을 포함하는 배열을 생성합니다.
x = np.array([-2.+2.j, -1.+2.j, 0.+2.j, 1.+2.j, 2.+2.j])
생성한 배열을 화면에 출력해 확인합니다.
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 다항식의 Vandermonde 행렬을 생성하기 위해 hermvander() 함수를 호출합니다.
print("\nResult...\n", H.hermvander(x, 2))전체 예제 코드
import numpy as np
from numpy.polynomial import hermite as H
# 복소수 값을 포함하는 배열 생성
x = np.array([-2.+2.j, -1.+2.j, 0.+2.j, 1.+2.j, 2.+2.j])
# 배열 출력
print("Our Array...\n", x)
# 차원 확인
print("\nDimensions of our Array...\n", x.ndim)
# 데이터 타입 확인
print("\nDatatype of our Array object...\n", x.dtype)
# 형태(shape) 확인
print("\nShape of our Array object...\n", x.shape)
# Hermite 다항식의 Vandermonde 행렬 생성
print("\nResult...\n", H.hermvander(x, 2))
실행 결과
Our Array...
[-2.+2.j -1.+2.j 0.+2.j 1.+2.j 2.+2.j]
Dimensions of our Array...
1
Datatype of our Array object...
complex128
Shape of our Array object...
(5,)
Result...
[[ 1. +0.j -4. +4.j -2.-32.j]
[ 1. +0.j -2. +4.j -14.-16.j]
[ 1. +0.j 0. +4.j -18. +0.j]
[ 1. +0.j 2. +4.j -14.+16.j]
[ 1. +0.j 4. +4.j -2.+32.j]]
정리
위 예제에서 알 수 있듯이, 입력 배열에 복소수가 포함되어 있으면 dtype이 자동으로 complex128로 변환됩니다. hermvander() 함수는 각 점 x에 대해 차수 0부터 지정된 차수(deg)까지의 Hermite 다항식 값을 계산하여 행렬의 열로 배치합니다. 이렇게 생성된 Vandermonde 행렬은 Hermite 다항식 기반의 최소제곱 피팅(least squares fitting)이나 다항식 근사 계산에 유용하게 활용할 수 있습니다.