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

Python NumPy hermpow()로 에르미트(Hermite) 급수 거듭제곱 계산하기

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

여기서 인자 c는 낮은 차수부터 높은 차수 순으로 정렬된 계수 시퀀스입니다. 예를 들어 [1, 2, 3]은 P_0 + 2*P_1 + 3*P_2라는 급수를 의미합니다.

hermpow() 메서드의 매개변수

  • c: 낮은 차수에서 높은 차수 순으로 정렬된 에르미트 급수 계수를 담고 있는 1차원 배열입니다.
  • pow: 급수를 거듭제곱할 지수(멱)입니다.
  • maxpower: 허용되는 최대 거듭제곱 값입니다. 이는 급수가 감당할 수 없을 정도로 커지는 것을 방지하기 위한 제한 장치이며, 기본값은 16입니다.

단계별 구현 방법

1단계: 필요한 라이브러리 임포트

먼저 필요한 라이브러리를 가져옵니다.

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

2단계: 에르미트 급수 계수 배열 생성

에르미트 급수의 계수를 담은 1차원 배열을 생성합니다.

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

3단계: 배열 정보 확인

생성한 계수 배열과 차원, 데이터 타입, 형태(shape)를 출력하여 확인합니다.

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

4단계: hermpow()로 거듭제곱 계산

polynomial.hermite.hermpow() 메서드를 사용해 에르미트 급수를 거듭제곱합니다. 아래 예시에서는 세제곱(pow=3)을 계산합니다.

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

전체 예제 코드

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

# 에르미트 급수 계수 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)

# hermpow() 메서드로 에르미트 급수를 거듭제곱
# 이 메서드는 거듭제곱된 에르미트 급수를 반환합니다.
print("\nResult....\n",H.hermpow(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....
   [2257. 2358. 3837. 908. 711. 54. 27.]

실행 결과를 보면 원래 3개의 계수를 가졌던 에르미트 급수가 세제곱되면서 7개의 계수를 가진 새로운 에르미트 급수로 확장된 것을 확인할 수 있습니다. 이처럼 hermpow() 메서드를 활용하면 복잡한 다항식 연산을 간단하게 처리할 수 있습니다.