NumPy Polynomials

Fit and evaluate mathematical polynomial functions with np.polynomial.

NumPy provides convenient classes to work with polynomials: creating, evaluating, finding roots, and least-squares fitting of polynomial curves to data points.

Key Takeaways: NumPy Polynomials

Mastering NumPy Polynomials helps you write clean and reliable NumPy code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

NumPy Polynomials Code Example

NumPy
import numpy as np
from numpy.polynomial import Polynomial

# Represents: 2x^2 + 3x + 1
p = Polynomial([1, 3, 2])
print("Evaluate at x=2:", p(2))
print("Roots of polynomial:", p.roots())
Output
Evaluate at x=2: 15.0
Roots of polynomial: [-1.  -0.5]
Free sign-in required · Google login available
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services