In this article, we will discuss how to evaluate a Hermite_e series at points x when coefficients are multi-dimensional in Python
We use the hermite.hermeval() function from the numpy module.
Syntax: hermite_e.hermeval(x,Arr)
Parameters :
- x (required parameter): ‘x’ can be a single number or list of numbers but the only condition is the ‘x’ or the elements in ‘x’ should support the operations like addition and multiplication among themselves and with the elements in ‘Arr’
(which is the second parameter to be passed). ‘x’ will be transformed to ndarray if it is a tuple or a list, otherwise it will consider as a scaler.- Arr (required parameter): ‘Arr’ is an array of coefficients that is sorted in such a way that the coefficients for terms of degree n
are present in Arr[n]. In our case the array is multi-dimensional array of coefficients.
Stepwise Implementation
Step 1: Import NumPy and hermite_e libraries :
import numpy as np from numpy.polynomial import hermite_e as H
Step 2: Now we have to create a multidimensional array ‘Arr’ of coefficients with any of style as shown below :
Arr = np.arange(4).reshape(2,2) OR Arr = np.matrix([[0,1],[2,3]]) OR Arr = [[0,1],[2,3]]
Step 3: To evaluate a Hermite_e series at points x for multidimensional coefficients, use the hermite.hermeval() method in Numpy module as shown below :
print(H.hermeval([1,2],Arr))
Example 1 :
Python3
# import numpy and hermite_e libraries import numpy as np from numpy.polynomial import hermite_e as HE # Create a multidimensional array 'Arr' # of coefficients Arr = np.matrix([[ 1 , 3 ], [ 4 , 5 ]]) # To evaluate a Hermite_e series at points # x for multidimensional coefficient array 'Arr', # use the hermite.hermeval() method in # Python Numpy print (HE.hermeval([ 2 , 3 ], Arr)) |
Output :
[[ 9. 13.] [13. 18.]]
Example 2 :
Python3
# import hermite_e library from numpy.polynomial import hermite_e as H # create a multidimensional array Mul_Array = [[ 2 , 2 ], [ 4 , 3 ]] # evaluate hermite_e series and print # the result print (H.hermeval([ 2 , 1 ], Mul_Array)) |
Output :
[[10. 6.] [ 8. 5.]]