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 2-D Chebyshev series on the Cartesian product of x and y with 1d array of coefficient in Python
To evaluate a 2-D Chebyshev series on the Cartesian product of x and y, use the polynomial.chebgrid2d(x, y, c) method in Python. The method returns values of the two-dimensional Chebyshev series at points in the Cartesian product of x and y. If c has fewer than two dimensions, ones are implicitly appended to its shape to make it 2-D.
Syntax
numpy.polynomial.chebyshev.chebgrid2d(x, y, c)
Parameters
- x, y − The two-dimensional series is evaluated at points in the Cartesian product of x and y. If x or y is a list or tuple, it is first converted to an ndarray
- c − Array of coefficients ordered so that the coefficient of the term of multi-degree i,j is contained in c[i,j]
Example
Let's create a 1D array of coefficients and evaluate the 2-D Chebyshev series ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a 1d array of coefficients
c = np.array([3, 5])
# 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)
# To evaluate a 2-D Chebyshev series on the Cartesian product of x and y
print("\nResult...\n", C.chebgrid2d([1,2], [1,2], c))
Our Array... [3 5] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (2,) Result... [21. 34.]
Using 2D Coefficient Array
Let's see how it works with a 2D coefficient array ?
import numpy as np
from numpy.polynomial import chebyshev as C
# Create a 2D array of coefficients
c = np.array([[1, 2], [3, 4]])
print("2D Coefficient Array:\n", c)
# Evaluate on different x and y points
x_points = [0, 1]
y_points = [0, 1]
result = C.chebgrid2d(x_points, y_points, c)
print("\nResult shape:", result.shape)
print("Result:\n", result)
2D Coefficient Array: [[1 2] [3 4]] Result shape: (2, 2) Result: [[ 0. -2.] [ 6. 0.]]
How It Works
The function evaluates the Chebyshev series for each combination of x and y values. For a 1D coefficient array like [3, 5], it creates a 2D series where:
- The coefficient array is treated as a column vector
- Each (x,y) pair from the Cartesian product is evaluated
- The result shape is determined by the input arrays' shapes
Conclusion
Use numpy.polynomial.chebyshev.chebgrid2d() to evaluate 2-D Chebyshev series on Cartesian products. The function automatically handles dimension expansion and returns results for all x,y combinations efficiently.
