bundles / numpy 2.4.4 / numpy / poly
_ArrayFunctionDispatcher
numpy:poly
Signature
def poly ( seq_of_zeros ) Summary
Find the coefficients of a polynomial with the given sequence of roots.
Extended Summary
Returns the coefficients of the polynomial whose leading coefficient is one for the given sequence of zeros (multiple roots must be included in the sequence as many times as their multiplicity; see Examples). A square matrix (or array, which will be treated as a matrix) can also be given, in which case the coefficients of the characteristic polynomial of the matrix are returned.
Parameters
seq_of_zeros: array_like, shape (N,) or (N, N)A sequence of polynomial roots, or a square array or matrix object.
Returns
c: ndarray1D array of polynomial coefficients from highest to lowest degree:
c[0] * x**(N) + c[1] * x**(N-1) + ... + c[N-1] * x + c[N]where c[0] always equals 1.
Raises
: ValueErrorIf input is the wrong shape (the input must be a 1-D or square 2-D array).
Notes
Specifying the roots of a polynomial still leaves one degree of freedom, typically represented by an undetermined leading coefficient. [1] In the case of this function, that coefficient - the first one in the returned array - is always taken as one. (If for some reason you have one other point, the only automatic way presently to leverage that information is to use polyfit.)
The characteristic polynomial, , of an n-by-n matrix A is given by
,
where I is the n-by-n identity matrix. [2]
Examples
Given a sequence of a polynomial's zeros:import numpy as np
✓np.poly((0, 0, 0)) # Multiple root example
✓np.poly((-1./2, 0, 1./2))
✓np.poly((np.random.random(1)[0], 0, np.random.random(1)[0]))
✗P = np.array([[0, 1./3], [-1./2, 0]]) np.poly(P)✓
See also
Aliases
-
numpy.poly