Evaluate a 3-D Chebyshev series on the Cartesian product of x, y and z with 4d array of coefficient in Python
In this article, we will discuss how to Evaluate a 3-D Chebyshev series on the Cartesian product of x, y, and z with a 4d array of coefficients in Python and NumPy.
NumPy.polynomial.chebyshev.chebgrid3d method
Chebyshev polynomials are significant in approximation theory because the Chebyshev nodes are used as matching points for optimizing polynomial interpolation.
To perform Chebyshev differentiation, NumPy provides a function called Chebyshev.chebgrid3d which can be used to evaluate the cartesian product of the 3D Chebyshev series. This function converts the parameters x, y, and z to array only if they are tuples or a list, otherwise, it is left unchanged and, if it is not an array, it is treated as a scalar.
Syntax: polynomial.chebyshev.chebgrid3d(x, y, z, c)
Parameters:
- x,y,z: array_like
- c: array of coefficients
Returns:
- Two dimensional polynomials at points as cartesian products of x and y.
Example 1:
In the first example. let us consider a 4D array c of size 32. Let us consider a 3D series [1,2],[1,2],[1,2] to evaluate against the 4D array. Import the necessary packages as shown and pass the appropriate parameters as shown below.
Python3
import numpy as np
from numpy.polynomial import chebyshev
c = np.arange( 32 ).reshape( 2 , 2 , 4 , 2 )
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 = chebyshev.chebgrid3d([ 1 , 2 ], [ 1 , 2 ], [ 1 , 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 27]
[28 29]
[30 31]]]]
The shape of the array is (2, 2, 4, 2)
The dimension of the array is 4D
The datatype of the array is int32
Resultant series ---> [[[[ 240. 2480.]
[ 392. 4008.]]
[[ 424. 4296.]
[ 684. 6876.]]]
[[[ 256. 2624.]
[ 416. 4224.]]
[[ 448. 4512.]
[ 720. 7200.]]]]
Example 2:
In the second example. let us consider a 4D array c of size 64. Let us consider a 3D series [2,1],[2,1],[2,1] to evaluate against the 4D array. Import the necessary packages as shown and pass the appropriate parameters as shown below.
Python3
import numpy as np
from numpy.polynomial import chebyshev
c = np.arange( 64 ).reshape( 4 , 4 , 2 , 2 )
print (f 'The co.efficient array is \n{c}\n' )
print (f 'The shape of the array is \n{c.shape}\n' )
print (f 'The dimension of the array is \n{c.ndim}D\n' )
print (f 'The datatype of the array is \n{c.dtype}\n' )
res = chebyshev.chebgrid3d([ 2 , 1 ], [ 2 , 1 ], [ 2 , 1 ], 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 27]] [[28 29] [30 31]]
[[[32 33] [34 35]] [[36 37][38 39]]
[[40 41] [42 43]] [[44 45][46 47]]]
[[[48 49] [50 51]] [[52 53][54 55]]
[[56 57] [58 59]] [[60 61][62 63]]]]
The shape of the array is (4, 4, 2, 2)
The dimension of the array is 4D
The datatype of the array is int32
Resultant series —> [[[[208224. 137952.][ 21216. 14048.]] [[ 15456. 10208.][ 1504. 992.]]]
[[[212112. 140544.][ 21648. 14336.]] [[ 15888. 10496.] [ 1552. 1024.]]]]
Last Updated :
22 Apr, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...