x와 y의 데카르트 곱(Cartesian product) 위에서 2차원 에르미트(Hermite) 급수를 평가하려면 Python의 hermite.hermgrid2d(x, y, c) 메서드를 사용합니다. 이 메서드는 x와 y의 데카르트 곱으로 이루어진 각 점에서 2차원 다항식의 값을 계산하여 반환합니다.
주요 매개변수
x, y : 2차원 급수가 평가될 점들로, x와 y의 데카르트 곱 위에서 계산이 수행됩니다. x 또는 y가 리스트(list)나 튜플(tuple)이면 먼저 ndarray로 변환되며, ndarray가 아니면 스칼라(scalar)로 취급됩니다.
c : 계수(coefficient) 배열로, 차수 i, j에 해당하는 항의 계수들이 c[i, j]에 저장되어 있어야 합니다. 만약 c의 차원이 2보다 크다면, 나머지 인덱스들은 여러 개의 계수 집합을 나타냅니다. 반대로 c의 차원이 2 미만이면, 형태를 2차원으로 맞추기 위해 1(ones)이 암묵적으로 추가됩니다. 결과의 형태(shape)는 c.shape[2:] + x.shape가 됩니다.
단계별 구현 방법
먼저 필요한 라이브러리를 임포트합니다.
import numpy as np
from numpy.polynomial import hermite as H
2차원 계수 배열을 생성합니다.
c = np.arange(4).reshape(2,2)
배열을 화면에 출력합니다.
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)x와 y의 데카르트 곱 위에서 2차원 에르미트 급수를 평가하려면 hermite.hermgrid2d(x, y, c) 메서드를 사용합니다.
print("\nResult...\n",H.hermgrid2d([1,2],[1,2], c))전체 예제 코드
import numpy as np
from numpy.polynomial import hermite as H
# 2차원 계수 배열 생성
c = np.arange(4).reshape(2,2)
# 배열 출력
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)
# hermgrid2d 메서드로 데카르트 곱 위에서 2차원 에르미트 급수 평가
print("\nResult...\n",H.hermgrid2d([1,2],[1,2], c))
실행 결과
Our Array...
[[0 1]
[2 3]]
Dimensions of our Array...
2
Datatype of our Array object...
int64
Shape of our Array object...
(2, 2)
Result...
[[18. 32.]
[34. 60.]]
위 결과를 보면, 계수 배열 [[0, 1], [2, 3]]을 사용하여 점 (1,1), (1,2), (2,1), (2,2)에서 각각 18.0, 32.0, 34.0, 60.0이라는 평가 값이 계산된 것을 확인할 수 있습니다. 이처럼 hermgrid2d 메서드를 활용하면 그리드 형태의 좌표 조합에 대해 2차원 에르미트 급수를 효율적으로 한 번에 평가할 수 있습니다.