Computer >> 컴퓨터 >  >> 프로그래밍 >> Python

Python NumPy chebval3d()로 점(x, y, z)에서 3차원 체비쇼프 급수 평가하기

Python NumPy의 polynomial.chebval3d() 메서드를 사용하면 점 (x, y, z)에서 3차원 체비쇼프(Chebyshev) 급수를 손쉽게 평가할 수 있습니다. 이 메서드는 x, y, z에서 대응하는 값들의 조합으로 만들어진 점들에 대해 다차원 다항식의 값을 반환합니다.

chebval3d() 메서드의 매개변수

x, y, z: 3차원 급수가 평가될 점 (x, y, z)입니다. 세 값은 반드시 동일한 형태(shape)를 가져야 합니다. 리스트나 튜플이 전달되면 먼저 ndarray로 변환되며, ndarray가 아닌 경우 스칼라로 취급됩니다.

c: 계수 배열입니다. 다중 차수 i, j, k에 해당하는 항의 계수는 c[i, j, k]에 저장됩니다. c의 차원이 3보다 크면 나머지 인덱스는 여러 개의 계수 집합을 나타냅니다.

단계별 구현 방법

1. 필요한 라이브러리 임포트

import numpy as np
from numpy.polynomial import chebyshev as C

2. 계수용 2D 배열 생성

c = np.arange(4).reshape(2,2)

3. 배열 출력하기

print("Our Array...\n",c)

4. 배열의 차원 확인

print("\nDimensions of our Array...\n",c.ndim)

5. 데이터 타입 확인

print("\nDatatype of our Array object...\n",c.dtype)

6. 배열의 형태(shape) 확인

print("\nShape of our Array object...\n",c.shape)

7. chebval3d() 메서드로 3차원 체비쇼프 급수 평가

print("\nResult...\n",C.chebval3d([1,2],[1,2],[1,2], c))

전체 예제 코드

import numpy as np
from numpy.polynomial import chebyshev as C

# 계수용 2D 배열 생성
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)

# chebval3d() 메서드로 점 (x, y, z)에서 3차원 체비쇼프 급수 평가
print("\nResult...\n",C.chebval3d([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...
    [24. 42.]

실행 결과를 보면 2x2 형태의 계수 배열이 생성되었고, chebval3d() 메서드가 점 (1, 1, 1)과 (2, 2, 2)에서 각각 24.0과 42.0이라는 값을 반환한 것을 확인할 수 있습니다.