Subtract one Hermite series from another in Python

To subtract one Hermite series from another, use the polynomial.hermite.hermsub() method in Python NumPy. The method returns an array representing the Hermite series of their difference. It computes c1 - c2, where the sequences of coefficients are ordered from lowest to highest order terms, i.e., [1,2,3] represents the series P_0 + 2*P_1 + 3*P_2.

Syntax

numpy.polynomial.hermite.hermsub(c1, c2)

Parameters

c1, c2 ? 1-D arrays of Hermite series coefficients ordered from low to high degree.

Example

Let's create two Hermite series and subtract one from another ?

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)

# Subtract one Hermite series from another
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.]

How It Works

The hermsub() method performs element-wise subtraction of the coefficients. In our example:

? c1 = [1, 2, 3] represents 1*P_0 + 2*P_1 + 3*P_2
? c2 = [3, 2, 1] represents 3*P_0 + 2*P_1 + 1*P_2
? Result = [(1-3), (2-2), (3-1)] = [-2, 0, 2]

Different Array Sizes

The method can handle arrays of different lengths ?

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

# Arrays of different sizes
c1 = np.array([1, 2, 3, 4])
c2 = np.array([1, 2])

print("Array1:", c1)
print("Array2:", c2)
print("Difference:", H.hermsub(c1, c2))
Array1: [1 2 3 4]
Array2: [1 2]
Difference: [0. 0. 3. 4.]

Conclusion

The hermsub() method provides an efficient way to subtract Hermite series by performing element-wise subtraction of coefficients. It automatically handles arrays of different lengths by zero-padding the shorter array.

Updated on: 2026-03-26T19:49:07+05:30

180 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements