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
Selected Reading
Evaluate a Laguerre series at points x broadcast over the columns of the coefficient in Python
To evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method in Python NumPy. This function broadcasts evaluation points over coefficient columns when tensor=False.
Syntax
numpy.polynomial.laguerre.lagval(x, c, tensor=True)
Parameters
The function accepts three parameters ?
- x − Array of points at which to evaluate the series. Can be scalar, list, or array
- c − Array of coefficients ordered so that coefficients for degree n are in c[n]. For multidimensional arrays, remaining indices enumerate multiple polynomials
- tensor − If True (default), extends coefficient shape. If False, broadcasts x over coefficient columns
Understanding Broadcasting with tensor=False
When tensor=False, each evaluation point in x corresponds to a column in the coefficient array c. This is useful for evaluating different polynomials at different points.
import numpy as np
from numpy.polynomial import laguerre as L
# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)
# Display the array
print("Our Array...")
print(c)
# Check the Dimensions
print("\nDimensions of our Array...")
print(c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...")
print(c.dtype)
# Get the Shape
print("\nShape of our Array object...")
print(c.shape)
# Evaluate Laguerre series with tensor=False
print("\nResult...")
print(L.lagval([1,2], c, tensor=False))
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... [ 0. -2.]
How It Works
With tensor=False, the evaluation works as follows ?
- Point x[0]=1 evaluates polynomial with coefficients c[:,0] = [0,2]
- Point x[1]=2 evaluates polynomial with coefficients c[:,1] = [1,3]
Comparison of tensor Parameter
import numpy as np
from numpy.polynomial import laguerre as L
c = np.array([[0, 1], [2, 3]])
x = [1, 2]
print("tensor=False (broadcast):")
print(L.lagval(x, c, tensor=False))
print("\ntensor=True (default):")
print(L.lagval(x, c, tensor=True))
tensor=False (broadcast): [ 0. -2.] tensor=True (default): [[ 0. -1.] [-2. -5.]]
| Parameter | Shape Behavior | Use Case |
|---|---|---|
tensor=False |
Broadcasts x over columns | Different polynomials at different points |
tensor=True |
Extends coefficient shape | All polynomials at all points |
Conclusion
Use lagval() with tensor=False to evaluate different Laguerre polynomials at corresponding points. This broadcasting approach is efficient for paired evaluations of multiple polynomial series.
Advertisements
