파이썬 NumPy에서 두 개의 체비쇼프(Chebyshev) 급수를 서로 더하려면 numpy.polynomial.chebyshev.chebadd() 메서드를 사용하면 됩니다. 이 메서드는 두 급수의 합(c1 + c2)을 나타내는 체비쇼프 급수 배열을 반환합니다.
메서드에 전달되는 인자는 낮은 차수 항부터 높은 차수 항 순으로 정렬된 계수 시퀀스입니다. 예를 들어 [1, 2, 3]이라는 배열은 T_0 + 2*T_1 + 3*T_2라는 급수를 의미합니다. 매개변수 c1과 c2는 각각 낮은 차수부터 높은 차수 순으로 정렬된 체비쇼프 급수 계수를 담고 있는 1차원 배열입니다.
chebadd() 메서드 사용 단계
먼저 필요한 라이브러리를 임포트합니다.
import numpy as np
from numpy.polynomial import chebyshev as C
다음으로 체비쇼프 급수의 계수를 담은 1차원 배열을 생성합니다.
c1 = np.array([1,2,3])
c2 = np.array([3,2,1])
생성한 계수 배열을 화면에 출력합니다.
print("Array1...\n",c1)
print("\nArray2...\n",c2)배열의 데이터 타입(dtype)을 확인합니다.
print("\nArray1 datatype...\n",c1.dtype)
print("\nArray2 datatype...\n",c2.dtype)두 배열의 차원(ndim)을 확인합니다.
print("\nDimensions of Array1...\n",c1.ndim)
print("\nDimensions of Array2...\n",c2.ndim)두 배열의 형상(shape)을 확인합니다.
print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)마지막으로 polynomial.chebyshev.chebadd() 메서드를 호출하여 두 체비쇼프 급수를 더합니다.
print("\nResult (sum)....\n",C.chebadd(c1,c2))전체 예제 코드
import numpy as np
from numpy.polynomial import chebyshev as C
# 체비쇼프 급수 계수 1차원 배열 생성
c1 = np.array([1,2,3])
c2 = np.array([3,2,1])
# 계수 배열 출력
print("Array1...\n",c1)
print("\nArray2...\n",c2)
# 데이터 타입 확인
print("\nArray1 datatype...\n",c1.dtype)
print("\nArray2 datatype...\n",c2.dtype)
# 차원 확인
print("\nDimensions of Array1...\n",c1.ndim)
print("\nDimensions of Array2...\n",c2.ndim)
# 형상(shape) 확인
print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)
# chebadd() 메서드로 두 체비쇼프 급수 더하기
print("\nResult (sum)....\n",C.chebadd(c1,c2))
실행 결과
Array1...
[1 2 3]
Array2...
[3 2 1]
Array1 datatype...
int64
Array2 datatype...
int64
Dimensions of Array1...
1
Dimensions of Array2...
1
Shape of Array1...
(3,)
Shape of Array2...
(3,)
Result (sum)....
[4. 4. 4.]
실행 결과를 보면 두 배열 [1, 2, 3]과 [3, 2, 1]의 합으로 [4. 4. 4.]가 출력됩니다. 이는 T_0 + 2*T_1 + 3*T_2와 3*T_0 + 2*T_1 + T_2를 더한 결과가 4*T_0 + 4*T_1 + 4*T_2임을 의미합니다.