Is there a module in numpy which returns a polynomial object?

Viewed 34

Using

from numpy.polynomial import polynomial as f
f.polyfromroots([2,2])

returns

[ 4. -4.  1.]

(the coefficients).

However, I could like it to return the polynomial x^2-4x+4 as an object.

Is there any such module available?

1 Answers

There's Polynomial:

poly = f.Polynomial(f.polyfromroots([2,2]))

poly(np.array([3, 5]))
# array([1., 9.])
Related