numpy
has two sets of polynomial tools, one in the base numpy library, and another in numpy.polynomial
. Why are there two? Is one preferable over the other? Is this to maintain backwards compatibility perhaps, or are there significant differences I should be aware of?
For example, polyfit
and polyval
are found in both libraries and appear to use the same algorithm, but their parameters are different (they expect coefficients in opposite orders).
From numpy
:
def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False)
def polyval(p, x)
Coefficients are ordered from high to low degree.
From numpy.polynomial
:
def polyfit(x, y, deg, rcond=None, full=False, w=None)
def polyval(x, c, tensor=True)
Coefficients are ordered from low to high degree.
I ran across this in the docs:
Prior to NumPy 1.4, numpy.poly1d was the class of choice and it is still available in order to maintain backward compatibility. However, the newer Polynomial package is more complete than numpy.poly1d and its convenience classes are better behaved in the numpy environment. Therefore numpy.polynomial is recommended for new coding.