파이썬에서 x, y, z의 데카르트 곱(Cartesian product) 위에서 3차원 체비쇼프(Chebyshev) 급수를 평가하려면 polynomial.chebgrid3d(x, y, z) 메서드를 사용합니다. 만약 계수 배열 c가 3차원 미만이라면, 3차원 형태가 되도록 형태(shape)에 자동으로 1이 추가됩니다. 결과의 형태는 c.shape[3:] + x.shape + y.shape + z.shape가 됩니다.
주요 매개변수
x, y, z : 3차원 급수를 평가할 지점들로, x, y, z의 데카르트 곱 위의 좌표를 의미합니다. x, y 또는 z가 리스트(list)나 튜플(tuple)이면 먼저 ndarray로 변환되며, ndarray가 아니면 스칼라(scalar)로 취급됩니다.
c : 계수(coefficient) 배열입니다. 차수 i, j에 해당하는 계수들이 c[i,j]에 포함되도록 정렬되어 있습니다. c의 차원이 3보다 크면, 나머지 인덱스들은 여러 개의 계수 집합을 나타냅니다.
단계별 구현 방법
먼저 필요한 라이브러리를 임포트합니다.
import numpy as np
from numpy.polynomial import chebyshev as C
3차원 계수 배열을 생성합니다.
c = np.arange(16).reshape(2,2,4)
생성한 배열을 출력해 확인합니다.
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)chebgrid3d() 메서드를 사용하여 x, y, z의 데카르트 곱 위에서 3차원 체비쇼프 급수를 평가합니다.
print("\nResult...\n",C.chebgrid3d([1,2],[1,2],[1,2], c))전체 예제 코드
import numpy as np
from numpy.polynomial import chebyshev as C
# 3차원 계수 배열 생성
c = np.arange(16).reshape(2,2,4)
# 배열 출력
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)
# chebgrid3d() 메서드로 3차원 체비쇼프 급수 평가
print("\nResult...\n",C.chebgrid3d([1,2],[1,2],[1,2], c))
실행 결과
Our Array...
[[[ 0 1 2 3]
[ 4 5 6 7]]
[[ 8 9 10 11]
[12 13 14 15]]]
Dimensions of our Array...
3
Datatype of our Array object...
int64
Shape of our Array object...
(2, 2, 4)
Result...
[[[ 120. 1240.]
[ 196. 2004.]]
[[ 212. 2148.]
[ 342. 3438.]]]
위 실행 결과에서 볼 수 있듯이, chebgrid3d() 메서드는 각 축의 지점 조합마다 체비쇼프 다항식 값을 계산하여 3차원 배열 형태로 반환합니다. 이 메서드는 다차원 근사(approximation)나 보간(interpolation) 작업에서 유용하게 활용될 수 있습니다.