In this article, we will discuss how to evaluate a 2-D Chebyshev series at points (x, y) with 3D array of coefficient 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 Chebyshev series.
NumPy.polynomial.Chebyshev.chebgrid2d method
To perform Chebyshev differentiation, NumPy provides a function called Chebyshev.chebgrid2d which can be used to evaluate the cartesian product of the 2D Chebyshev 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: chebyshev.chebgrid2d(x,y, c)
Parameters:
- x,y: Input array.
- c: Array of coefficients ordered
Returns: Two dimensional Chebyshev 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 chebyshev # co.efficient array 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}' ) # evaluating co.eff array with a chebyshev series res = chebyshev.chebgrid2d([ 2 , 2 ], [ 2 , 2 ], c) # resultant array 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 int32 Resultant series ---> [[[1920. 1920.] [1920. 1920.]] [[2020. 2020.] [2020. 2020.]] [[2120. 2120.] [2120. 2120.]]]
Example 2:
In the first example. let us consider a 3D array c of size 27 and a series of [2,1],[2,1], to evaluate against the 2D array.
Python3
import numpy as np from numpy.polynomial import chebyshev # co.efficient array 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}' ) # evaluating co.eff array with a chebyshev series res = chebyshev.chebgrid2d([ 2 , 1 ], [ 2 , 1 ], c) # resultant array 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 int32 Resultant series ---> [[[1920. 522.] [ 414. 108.]] [[2020. 552.] [ 444. 117.]] [[2120. 582.] [ 474. 126.]]]