- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Evaluate a polynomial at points x and x is broadcast over the columns of r for the evaluation in Python

To evaluate a polynomial specified by its roots at points x, use the polynomial.polyvalfromroots() method in Python Numpy. The 1st parameter is x. If x is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar. In either case, x or its elements must support addition and multiplication with themselves and with the elements of r.

The 2nd parameter, r is an array of roots. If r is multidimensional the first index is the root index, while the remaining indices enumerate multiple polynomials. For instance, in the two dimensional case the roots of each polynomial may be thought of as stored in the columns of r.

The 3rd parameter is tensor. If True, the shape of the roots array is extended with ones on the right, one for each dimension of x. Scalars have dimension 0 for this action. The result is that every column of coefficients in r is evaluated for every element of x. If False, x is broadcast over the columns of r for the evaluation. This keyword is useful when r is multidimensional. The default value is True.

## Steps

At first, import the required libraries −

from numpy.polynomial.polynomial import polyvalfromroots import numpy as np

Create an array of multidimensional coefficients −

c = np.arange(-2, 2).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)

To evaluate a polynomial specified by its roots at points x, use the polynomial.polyvalfromroots() method in Python Numpy −

print("\nResult...\n",polyvalfromroots([-2, 1], c, tensor=False))

## Example

from numpy.polynomial.polynomial import polyvalfromroots import numpy as np # Create an array of multidimensional coefficients c = np.arange(-2, 2).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) # To evaluate a polynomial specified by its roots at points x, use the polynomial.polyvalfromroots() method in Python Numpy print("\nResult...\n",polyvalfromroots([-2, 1], c, tensor=False))

## Output

Our Array... [[-2 -1] [ 0 1]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [-0. 0.]

- Related Questions & Answers
- Evaluate a polynomial at points x broadcast over the columns of the coefficient in Python
- Evaluate a Chebyshev series at points x broadcast over the columns of the coefficient in Python
- Evaluate a Hermite series at points x broadcast over the columns of the coefficient in Python
- Evaluate a Laguerre series at points x broadcast over the columns of the coefficient in Python
- Evaluate a Legendre series at points x broadcast over the columns of the coefficient in Python
- Evaluate a Hermite_e series at points x broadcast over the columns of the coefficient in Python
- Evaluate a polynomial at points x in Python
- Evaluate a polynomial at points x and the shape of the coefficient array extended for each dimension of x in Python
- Evaluate a 2-D polynomial at points (x, y) in Python
- Evaluate a polynomial at points x with multidimensioanl array of roots in Python
- Evaluate a 3-D polynomial at points (x, y, z) in Python
- Evaluate a polynomial specified by its roots at points x in Python
- Evaluate a Hermite series at points x in Python
- Evaluate a Laguerre series at points x in Python
- Evaluate a Legendre series at points x in Python