x와 y의 데카르트 곱(Cartesian product) 위에서 2차원 체비쇼프(Chebyshev) 급수를 평가하려면 Python의 polynomial.chebgrid2d(x, y, c) 메서드를 사용하면 됩니다. 이 메서드는 x와 y의 데카르트 곱에 있는 점들에서 2차원 체비쇼프 급수의 값을 반환합니다.
계수 배열 c가 2차원보다 낮은 차원을 가지면, 형태(shape)에 길이가 1인 축이 암묵적으로 추가되어 2차원으로 변환됩니다. 결과의 형태는 c.shape[2:] + x.shape + y.shape가 됩니다.
매개변수 x와 y는 2차원 급수를 평가할 점들을 나타내며, 두 배열의 데카르트 곱 위에서 평가가 수행됩니다. x나 y가 리스트 또는 튜플이면 먼저 ndarray로 변환되고, ndarray가 아닌 값은 변경되지 않은 채 스칼라(scalar)로 취급됩니다.
매개변수 c는 다차수(multidegree) i, j에 해당하는 항의 계수가 c[i,j]에 담기도록 정렬된 계수 배열입니다. c의 차원이 2보다 크다면, 남는 인덱스들은 여러 개의 계수 집합을 나타냅니다.
chebgrid2d() 메서드의 주요 특징
- 반환값: x와 y의 데카르트 곱 점들에서 계산된 2차원 체비쇼프 급수의 값
- 결과 형태: c.shape[2:] + x.shape + y.shape
- 유연한 입력 처리: 리스트, 튜플, 스칼라 등 다양한 입력 형식 지원
단계별 구현 방법
먼저 필요한 라이브러리를 임포트합니다.
import numpy as np from numpy.polynomial import chebyshev as C
3차원 계수 배열을 생성합니다.
c = np.arange(24).reshape(2,2,6)
생성한 배열을 출력해 확인합니다.
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)
chebgrid2d() 메서드를 사용하여 x와 y의 데카르트 곱 위에서 2차원 체비쇼프 급수를 평가합니다.
print("\nResult...\n",C.chebgrid2d([1,2],[1,2], c))
전체 예제 코드
import numpy as np
from numpy.polynomial import chebyshev as C
# 3차원 계수 배열 생성
c = np.arange(24).reshape(2,2,6)
# 배열 출력
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)
# chebgrid2d() 메서드로 x와 y의 데카르트 곱 위에서 2차원 체비쇼프 급수 평가
print("\nResult...\n",C.chebgrid2d([1,2],[1,2], c))
실행 결과
Our Array... [[[ 0 1 2 3 4 5] [ 6 7 8 9 10 11]] [[12 13 14 15 16 17] [18 19 20 21 22 23]]] Dimensions of our Array... 3 Datatype of our Array object... int64 Shape of our Array object... (2, 2, 6) Result... [[[ 36. 60.] [ 66. 108.]] [[ 40. 66.] [ 72. 117.]] [[ 44. 72.] [ 78. 126.]] [[ 48. 78.] [ 84. 135.]] [[ 52. 84.] [ 90. 144.]] [[ 56. 90.] [ 96. 153.]]]