Open In App

Evaluate Hermite series at points x when coefficients are multi-dimensional using NumPy in Python

Last Updated : 13 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will cover how to evaluate a Hermite series at points x with a multidimensional coefficient array in Python using NumPy.

Example

Input: [[11 12][13 14]]
Output: [[37. 63.][40. 68.]]
Explanation: Hermite series at points x.

NumPy.polynomial.hermite.hermval method

To evaluate a Hermite series at points x with a multidimensional coefficient array, NumPy provides a function called hermite.hermval(). It takes two parameters x and c. whereas x is a tuple or list. It is considered a scalar. But, the parameter x should support multiplication and addition within itself and with the elements of c. If c is a 1-D array, then it will have the same shape as x. If c is multidimensional, then the shape of the result depends on the value of the tensor.

Syntax: polynomial.hermite.hermval(x,c, tensor)

Parameter:

  • x: array_like
  • c: Array of coefficient
  • tensor: boolean(optional).

Return: An Hermite series at points x.

Example 1:

In the first example, let us consider a 2D array and evaluate a Hermite series at point x. Import the necessary packages and pass the appropriate parameters as shown.

Python3




import numpy as np
from numpy.polynomial import hermite
 
# coefficient array
c = np.array([[11, 12], [13, 14]])
 
print(f'The coefficient array is {c}')
print(f'The shape of the array is {c.shape}')
print(f'The dimension of the array is {c.ndim}D')
print(f'The datatype of the array is {c.dtype}')
 
# evaluating multidimensal array of hermiteseries
res = hermite.hermval([1, 2], c)
 
# resultant array
print(f'Resultant series ---> {res}')


Output:

The coefficient array is 
[[11 12]
 [13 14]]

The shape of the array is (2, 2)
The dimension of the array is 2D
The datatype of the array is int32

Resultant series ---> 
[[37. 63.]
 [40. 68.]]

Example 2:

In the second example, let us consider a 3D array and evaluate a Hermite series at point x. Import the necessary packages and pass the appropriate parameters as shown

Python3




import numpy as np
from numpy.polynomial import hermite
 
# coefficient array
c = np.arange(27).reshape(3, 3, 3)
 
print(f'The coefficient array is {c}')
print(f'The shape of the array is {c.shape}')
print(f'The dimension of the array is {c.ndim}D')
print(f'The datatype of the array is {c.dtype}')
 
# evaluating multidimensal array of hermiteseries
res = hermite.hermval([17, 22], c)
 
# resultant array
print(f'Resultant series ---> {res}')


Output:

The coefficient array is 
[[[ 0  1  2]
  [ 3  4  5]
  [ 6  7  8]]

 [[ 9 10 11]
  [12 13 14]
  [15 16 17]]

 [[18 19 20]
  [21 22 23]
  [24 25 26]]]

The shape of the array is (3, 3, 3)
The dimension of the array is 3D
The datatype of the array is int32

Resultant series ---> 
[[[21078. 35208.]
  [22267. 37187.]
  [23456. 39166.]]

 [[24645. 41145.]
  [25834. 43124.]
  [27023. 45103.]]

 [[28212. 47082.]
  [29401. 49061.]
  [30590. 51040.]]]


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads