Evaluate a 2D Laguerre series at points (x,y) using NumPy in Python
Last Updated :
03 Jun, 2022
In this article, we will discuss how to evaluate a 2D Laguerre series at points (x,y) using NumPy in Python.
Example
Input: [[[ 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]]]
Output: [[[1920. 522.]
[ 414. 108.]]
[[2020. 552.]
[ 444. 117.]]
[[2120. 582.]
[ 474. 126.]]]
Explanation: Two dimensional Laguerre series.
NumPy.polynomial.laguerre.lagval2d method
To perform Laguerre differentiation, NumPy provides a function called laguerre.lagval2d which can be used to evaluate the cartesian product of the 2D Laguerre series. This function converts the parameters x and y to arrays only if they are tuples or a list and of the same shape, otherwise, it is left unchanged and, if it is not an array, it is treated as a scalar. If c has a dimension greater than 2 the remaining indices enumerate multiple sets of coefficients.
Syntax: laguerre.lagval2d(x,y, c)
Parameters:
- x,y: Input array.
- c: Array of coefficients ordered
Returns: Two dimensional Laguerre series at points in the Cartesian product of x and y.
Example 1:
In the first example. let us consider a 3D array c of size 27 and a series of [2,2],[2,2] to evaluate against the 2D array.
Python3
import numpy as np
from numpy.polynomial import laguerre
c = np.arange( 27 ).reshape( 3 , 3 , 3 )
print (f 'The co.efficient 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}' )
res = laguerre.lagval2d([ 2 , 2 ], [ 2 , 2 ], c)
print (f 'Resultant series ---> {res}' )
|
Output:
The co.efficient 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 int64
Resultant series ---> [[36. 36.]
[37. 37.]
[38. 38.]]
Example 2:
In the second example. let us consider a 2D array c of size 10 and a series of [2,2],[2,2] to evaluate against the 2D array.
Python3
import numpy as np
from numpy.polynomial import laguerre
c = np.array([[ 1 , 2 , 3 , 4 , 5 ],[ 45 , 56 , 65 , 55 , 55 ]])
print (f 'The co.efficient 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}' )
res = laguerre.lagval2d([ 2 , 2 ], [ 2 , 2 ], c)
print (f 'Resultant series ---> {res}' )
|
Output:
The co.efficient array is [[ 1 2 3 4 5]
[45 56 65 55 55]]
The shape of the array is (2, 5)
The dimension of the array is 2D
The datatype of the array is int64
Resultant series ---> [72.33333333 72.33333333]
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...