Python에서 x, y, z의 데카르트 곱(Cartesian product) 위에서 3차원 에르미트(Hermite) 급수를 평가하려면 hermite.hermgrid3d(x, y, z, c) 메서드를 사용하면 됩니다. 이 메서드는 x, y, z의 데카르트 곱으로 이루어진 각 점에서 삼차원 다항식의 값을 반환합니다.
매개변수 살펴보기
x, y, z: 삼차원 급수는 x, y, z의 데카르트 곱에 포함된 점들에서 평가됩니다. x, y 또는 z가 리스트(list)나 튜플(tuple)이라면 먼저 ndarray로 변환되고, 이미 ndarray라면 그대로 사용됩니다. 만약 ndarray가 아니라면 스칼라 값으로 취급됩니다.
c: 계수(coefficient) 배열입니다. 차수 i, j에 해당하는 항들의 계수가 c[i, j]에 담기도록 정렬되어 있습니다. c의 차원이 3보다 크다면 나머지 인덱스는 여러 개의 계수 집합을 나타내는 데 사용됩니다. 반대로 c의 차원이 3 미만이라면, 3차원이 되도록 형태(shape)에 1이 암묵적으로 추가됩니다. 결과 배열의 형태는 c.shape[3:] + x.shape + y.shape + z.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)배열의 데이터 타입(dtype)을 확인합니다.
print("\nDatatype of our Array object...\n", c.dtype)배열의 형태(shape)를 확인합니다.
print("\nShape of our Array object...\n", c.shape)x, y, z의 데카르트 곱 위에서 3차원 에르미트 급수를 평가하기 위해 hermite.hermgrid3d(x, y, z, c) 메서드를 호출합니다.
print("\nResult...\n", H.hermgrid3d([1, 2], [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)
# 형태(shape) 확인
print("\nShape of our Array object...\n", c.shape)
# x, y, z의 데카르트 곱 위에서 3차원 에르미트 급수 평가
print("\nResult...\n", H.hermgrid3d([1, 2], [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...
[[ 86. 154.]
[152. 272.]]