Saturday, December 28, 2024
Google search engine
HomeLanguagesDifferentiate a Hermite series with multidimensional coefficients in Python

Differentiate a Hermite series with multidimensional coefficients in Python

In this article, we will cover how to differentiate a Hermite series with multidimensional coefficients in Python using NumPy.

Example

Input: [[ 1  2  3  4  5]

 [ 3  4  2  6  7]

 [43 45  2  6  7]]

Output: [[  3.   4.   2.   6.   7.]

 [129. 135.   6.  18.  21.]]

Explanation: Hermite series of the derivative.

hermite.hermder method

To evaluate a Hermite series at points x with a multidimensional coefficient array, NumPy provides a function called hermite.hermder(). This method is used to generate the Hermite series and this method is available in the NumPy module in python, it returns a multi-dimensional coefficient array, Below is the syntax of the Hermite method.

Syntax: hermite.hermder(x, m, axis)

Parameter:

  • x: array
  • m: Number of derivatives taken, must be non-negative. (Default: 1)
  • axis: Axis over which the derivative is taken. (Default: 1).

Return: Hermite series.

Example 1:

In this example, we are creating a coefficient multi-dimensional array of 5 x 2 and, displaying the shape and dimensions of an array. Also, we are using hermite.hermder() method to differentiate a hermite series.

Python3




# import the numpy module
import numpy
  
# import hermite
from numpy.polynomial import hermite
  
# create array of coefficients with 5 elements
# each
coefficients_data = numpy.array([[1, 2, 3, 4, 5],
                                 [3, 4, 2, 6, 7]])
  
# Display the coefficients
print(coefficients_data)
  
# get the shape
print(f"\nShape of an array: {coefficients_data.shape}")
  
# get the dimensions
print(f"Dimension: {coefficients_data.ndim}")
  
# using  hermite.hermder() method to differentiate
# a Hermite series.
print("\nHermite series", hermite.hermder(coefficients_data))


Output:

[[1 2 3 4 5]
 [3 4 2 6 7]]

Shape of an array: (2, 5)
Dimension: 2

Hermite series [[ 6.  8.  4. 12. 14.]]

Example 2:

In this example, we are creating a coefficient multi-dimensional array of 5 x 3 and, displaying the shape and dimensions of an array. Also, we are using the number of derivatives=2, and the axis over which the derivative is taken is 1.

Python3




# import the numpy module
import numpy
  
# import hermite
from numpy.polynomial import hermite
  
# create array of coefficients with 5 elements each
coefficients_data = numpy.array(
    [[1, 2, 3, 4, 5], [3, 4, 2, 6, 7], [43, 45, 2, 6, 7]])
  
# Display the coefficients
print(coefficients_data)
  
# get the shape
print(f"\nShape of an array: {coefficients_data.shape}")
  
# get the dimensions
print(f"Dimension: {coefficients_data.ndim}")
  
# using  hermite.hermder() method to differentiate a Hermite series.
print("\nHermite series", hermite.hermder(coefficients_data, m=2, axis=1))


Output:

[[ 1  2  3  4  5]
 [ 3  4  2  6  7]
 [43 45  2  6  7]]

Shape of an array: (3, 5)
Dimension: 2

Hermite series [[ 24.  96. 240.]
 [ 16. 144. 336.]
 [ 16. 144. 336.]]

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments