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 with 2d array of coefficient in Python
To evaluate a 3-D Chebyshev series on the Cartesian product of x, y, z, use the polynomial.chebgrid3d() method in Python. This function evaluates a multidimensional Chebyshev series at points formed by the Cartesian product of the input arrays.
Understanding the Parameters
The chebgrid3d(x, y, z, c) method takes four parameters:
- x, y, z − The coordinates where the 3-D series is evaluated. 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 are in c[i,j]. If c has fewer than three dimensions, ones are implicitly appended to make it 3-D
The shape of the result will be c.shape[3:] + x.shape + y.shape + z.shape.
Example
Let's create a 2D coefficient array and evaluate the 3-D Chebyshev series ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a 2d array of coefficients
c = np.arange(4).reshape(2,2)
# Display the array
print("Our Array...\n", c)
# Check the Dimensions
print("\nDimensions of our Array...\n", c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n", c.dtype)
# Get the Shape
print("\nShape of our Array object...\n", c.shape)
# Evaluate 3-D Chebyshev series on Cartesian product
print("\nResult...\n", C.chebgrid3d([1,2], [1,2], [1,2], c))
Our Array... [[0 1] [2 3]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [[17. 28.] [28. 46.]]
How It Works
The function evaluates the Chebyshev polynomial at each point in the Cartesian product of the input coordinates. Since we provided a 2D coefficient array, the function automatically extends it to 3D by adding a dimension of size 1.
Different Coordinate Arrays
You can also use different coordinate arrays for each dimension ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create coefficient array
c = np.array([[1, 2], [3, 4]])
# Use different coordinate arrays
x = [0, 1]
y = [0, 1, 2]
z = [1]
result = C.chebgrid3d(x, y, z, c)
print("Result shape:", result.shape)
print("Result:\n", result)
Result shape: (2, 3, 1) Result: [[[10.] [10.] [18.]]]
Conclusion
The chebgrid3d() function provides an efficient way to evaluate 3-D Chebyshev series on Cartesian product grids. The function automatically handles dimension expansion and returns results with predictable shape based on input dimensions.
