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

Python NumPy의 hermepow()로 Hermite_e 급수 거듭제곱 계산하기

Hermite_e(헤르미트_e) 급수를 거듭제곱하려면 Python NumPy에서 제공하는 polynomial.hermite.hermepow() 메서드를 사용하면 됩니다. 이 메서드는 주어진 Hermite_e 급수를 지정한 거듭제곱만큼 올린 결과를 새로운 Hermite_e 급수 형태로 반환합니다.

인자 c는 낮은 차수부터 높은 차수 순으로 정렬된 계수 시퀀스입니다. 예를 들어 [1, 2, 3]은 P_0 + 2*P_1 + 3*P_2라는 급수를 의미합니다. 또한 maxpower 매개변수를 통해 허용되는 최대 거듭제곱을 제한할 수 있으며, 기본값은 16입니다. 이는 급수가 감당하기 어려운 크기로 무한정 커지는 것을 방지하기 위한 안전장치입니다.

주요 매개변수

  • c : 낮은 차수부터 높은 차수 순으로 정렬된 Hermite_e 급수 계수를 담고 있는 1차원 배열입니다.
  • pow : 급수를 거듭제곱할 지수입니다.
  • maxpower : 허용되는 최대 거듭제곱입니다. 기본값은 16이며, 급수 크기의 비정상적인 증가를 막는 역할을 합니다.

단계별 구현 방법

먼저 필요한 라이브러리를 임포트합니다.

import numpy as np
from numpy.polynomial import hermite_e as H

Hermite_e 급수의 계수를 담은 1차원 배열을 생성합니다.

c = np.array([1,2,3])

생성한 계수 배열을 출력해 확인합니다.

print("Our coefficient 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)

이제 hermepow() 메서드를 사용해 Hermite_e 급수를 거듭제곱합니다.

print("\nResult....\n",H.hermepow(c, 3))

전체 예제 코드

import numpy as np
from numpy.polynomial import hermite_e as H

# Hermite_e 급수 계수를 담은 1차원 배열 생성
c = np.array([1,2,3])

# 계수 배열 출력
print("Our coefficient 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)

# hermepow() 메서드로 Hermite_e 급수를 3제곱하여 결과 출력
print("\nResult....\n",H.hermepow(c, 3))

실행 결과

Our coefficient Array...
    [1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(3,)

Result....
    [ 355. 642. 1119. 476. 387. 54. 27.]

실행 결과를 보면 [1, 2, 3]으로 표현된 Hermite_e 급수를 3제곱했을 때, 7개의 계수를 가진 새로운 Hermite_e 급수가 반환되는 것을 확인할 수 있습니다. 이처럼 hermepow() 메서드를 활용하면 복잡한 다항식 연산을 간단하게 처리할 수 있습니다.