This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / roots

_ArrayFunctionDispatcher

numpy:roots

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_polynomial_impl.py :170

Signature

def   roots ( p )

Summary

Return the roots of a polynomial with coefficients given in p.

Extended Summary

The values in the rank-1 array p are coefficients of a polynomial. If the length of p is n+1 then the polynomial is described by

p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]

Parameters

p : array_like

Rank-1 array of polynomial coefficients.

Returns

out : ndarray

An array containing the roots of the polynomial.

Raises

: ValueError

When p cannot be converted to a rank-1 array.

Notes

The algorithm relies on computing the eigenvalues of the companion matrix [1].

Examples

import numpy as np
coeff = [3.2, 2, 1]
np.roots(coeff)

See also

poly

Find the coefficients of a polynomial with a given sequence of roots.

poly1d

A one-dimensional polynomial class.

polyfit

Least squares polynomial fit.

polyval

Compute polynomial values.

Aliases

  • numpy.roots