Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Evaluate a 3-D Chebyshev series on the Cartesian product of x, y and z in Python
To evaluate a 3-D Chebyshev series on the Cartesian product of x, y, z, use the numpy.polynomial.chebyshev.chebgrid3d() method in Python. This function computes the Chebyshev polynomial values at all combinations of the input coordinate arrays.
The chebgrid3d() method takes coordinate arrays x, y, z and evaluates the 3-D Chebyshev series at their Cartesian product. If the coefficient array c has fewer than three dimensions, ones are implicitly appended to make it 3-D. The result shape will be c.shape[3:] + x.shape + y.shape + z.shape.
Syntax
numpy.polynomial.chebyshev.chebgrid3d(x, y, z, c)
Parameters
x, y, z: Arrays of coordinates where the series is evaluated. The Chebyshev series is evaluated at the Cartesian product of these points. If any parameter is a list or tuple, it's converted to an ndarray.
c: Array of coefficients ordered so that coefficients for terms of degree i,j,k are contained in c[i,j,k]. If c has more than three dimensions, the remaining indices enumerate multiple coefficient sets.
Example
Let's create a 3D coefficient array and evaluate the Chebyshev series ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a 3D array of coefficients
c = np.arange(16).reshape(2, 2, 4)
# Display the coefficient array
print("Coefficient Array:")
print(c)
print(f"\nShape: {c.shape}")
print(f"Dimensions: {c.ndim}")
print(f"Datatype: {c.dtype}")
Coefficient Array: [[[ 0 1 2 3] [ 4 5 6 7]] [[ 8 9 10 11] [12 13 14 15]]] Shape: (2, 2, 4) Dimensions: 3 Datatype: int64
Evaluating the 3-D Chebyshev Series
Now evaluate the series on the Cartesian product of coordinate points ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create coefficient array
c = np.arange(16).reshape(2, 2, 4)
# Evaluate at Cartesian product of [1,2] x [1,2] x [1,2]
result = C.chebgrid3d([1, 2], [1, 2], [1, 2], c)
print("Result shape:", result.shape)
print("Evaluation result:")
print(result)
Result shape: (2, 2, 2) Evaluation result: [[[120. 196.] [212. 342.]] [[1240. 2004.] [2148. 3438.]]]
Different Coordinate Arrays
You can use different coordinate arrays for each dimension ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a simpler 2x2x2 coefficient array
c = np.arange(8).reshape(2, 2, 2)
print("Coefficient array:")
print(c)
# Use different coordinates for x, y, z
x_coords = [0, 1]
y_coords = [0]
z_coords = [0, 1, 2]
result = C.chebgrid3d(x_coords, y_coords, z_coords, c)
print(f"\nResult shape: {result.shape}")
print("Result:")
print(result)
Coefficient array: [[[0 1] [2 3]] [[4 5] [6 7]]] Result shape: (2, 1, 3) Result: [[[4. 5. 8.]]]
Key Points
- The function evaluates at the Cartesian product of input coordinates
- Coefficient array c should be at least 3-dimensional
- Result shape combines coefficient dimensions beyond the first 3 with coordinate array shapes
- Input coordinates can be lists, tuples, or arrays
Conclusion
The chebgrid3d() method efficiently evaluates 3-D Chebyshev series on coordinate grids. It's useful for multivariate polynomial approximation and scientific computing applications requiring Chebyshev polynomial evaluations.
