In this article, we will cover how to differentiate a Hermite_e series and set derivatives in Python using NumPy.
np.polynomial.hermite_e.hermeder method:
To Differentiate a Hermite series in python we use the NumPy.polynomial.hermite_e.hermeder() method which is used to return the c differentiated m times along the axis series coefficients. Where, the argument c is an array of coefficients ranging in degree from low to high along each axis, such as [3,1,2], which represents the series 3*He 0 + 1*He 1 + 2*He 2. Below is the syntax of the hermeder method.
Syntax: numpy.polynomial.hermite_e.hermeder(c, m=1, scl=1, axis=0)
Parameters:
- c: array like object.
- m: int, optional value. The total number of derivatives taken must not be negative. (Standard: 1).
- axis: int , optional value. The axis on which the derivative is computed. (The default is 0).
Return: The derivative of Hermite series.
Example 1:
Here, we will create a NumPy array and use numpy.polynomial.hermite_e.hermeder() to differentiate the Hermite series and set the derivatives. The shape of the array is found by the .shape attribute, the dimension of the array is found by .ndim attribute, and the data type of the array is .dtype attribute. In the below example, the number of derivatives set is 2, for the given coefficients.
Python3
# import packages import numpy as np from numpy.polynomial import hermite_e as H # Creating an array array = np.array([ 4 , 3 , 5 ]) print (array) # shape of the array is print ( "Shape of the array is: " , array.shape) # dimension of the array print ( "The dimension of the array is: " , array.ndim) # datatype of the array print ( "Datatype of our Array is: " , array.dtype) # differenciating a hermite series and setting # derivatives print (H.hermeder(array,m = 2 )) |
Output:
[4 3 5] Shape of the array is: (3,) The dimension of the array is: 1 Datatype of our Array is: int64 [10.]
Example 2:
In this example, the number of dedicates set is 2, the axis is set to ‘1’ which says the derivatives are computed along with the columns.
Python3
# import packages import numpy as np from numpy.polynomial import hermite_e as H # Creating an array array = np.array([[ 4 , 3 , 5 ],[ 6 , 7 , 8 ]]) print (array) # shape of the array is print ( "Shape of the array is: " , array.shape) # dimension of the array print ( "The dimension of the array is: " , array.ndim) # datatype of the array print ( "Datatype of our Array is: " , array.dtype) # differenciating a hermite series and setting # derivatives print (H.hermeder(array,m = 2 ,axis = 1 )) |
Output:
[[4 3 5] [6 7 8]] Shape of the array is: (2, 3) The dimension of the array is: 2 Datatype of our Array is: int64 [[10.] [16.]]