Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python의 다른 Hermite 시리즈에서 하나의 Hermite 시리즈 빼기

<시간/>

하나의 Hermite 계열을 다른 계열로 빼려면 PythonNumpy에서 polynomial.hermite.hermsub() 메서드를 사용합니다. 이 메서드는 차이의 Hermite 계열을 나타내는 배열을 반환합니다. 두 Hermite 계열 c1 - c2의 차이를 반환합니다. 계수의 시퀀스는 가장 낮은 차수에서 가장 높은 것까지입니다. 즉, [1,2,3]은 시리즈 P_0 + 2*P_1 + 3*P_2를 나타냅니다. 매개변수 c1 및 c2는 낮은 값에서 높은 순서로 정렬된 Hermite 계열 계수의 1차원 배열입니다.

단계

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

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

Hermite 시리즈 계수의 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)

두 배열의 모양을 확인하십시오 -

print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)

하나의 Hermite 시리즈를 다른 시리즈로 빼려면 Python Numpy에서 polynomial.hermite.hermsub() 메서드를 사용하십시오 -

print("\nResult (difference)....\n",H.hermsub(c1, c2))

예시

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

# Create 1-D arrays of Hermite series coefficients
c1 = np.array([1,2,3])
c2 = np.array([3,2,1])

# Display the arrays of coefficients
print("Array1...\n",c1)
print("\nArray2...\n",c2)

# Display the datatype
print("\nArray1 datatype...\n",c1.dtype)
print("\nArray2 datatype...\n",c2.dtype)

# Check the Dimensions of both the arrays
print("\nDimensions of Array1...\n",c1.ndim)
print("\nDimensions of Array2...\n",c2.ndim)

# Check the Shape of both the arrays
print("\nShape of Array1...\n",c1.shape)
print("\nShape of Array2...\n",c2.shape)

# To subtract one Hermite series to another, use the polynomial.hermite.hermsub() method in Python Numpy
# The method returns an array representing the Hermite series of their difference.
print("\nResult (difference)....\n",H.hermsub(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 (difference)....
   [-2. 0. 2.]