[Numpydiscussion] Polynomial evaluation inconsistencies
Maxwell Aifer
maifer at haverford.edu
Fri Jun 29 22:21:18 EDT 2018
Hi,
I noticed some frustrating inconsistencies in the various ways to evaluate
polynomials using numpy. Numpy has three ways of evaluating polynomials
(that I know of) and each of them has a different syntax:

numpy.polynomial.polynomial.Polynomial
<https://docs.scipy.org/doc/numpy1.13.0/reference/generated/numpy.polynomial.polynomial.Polynomial.html#numpy.polynomial.polynomial.Polynomial>:
You define a polynomial by a list of coefficients *in order of
increasing degree*, and then use the class’s call() function.

np.polyval
<https://docs.scipy.org/doc/numpy1.13.0/reference/generated/numpy.polyval.html>:
Evaluates a polynomial at a point. *First* argument is the polynomial,
or list of coefficients *in order of decreasing degree*, and the *second*
argument is the point to evaluate at.

np.polynomial.polynomial.polyval
<https://docs.scipy.org/doc/numpy1.12.0/reference/generated/numpy.polynomial.polynomial.polyval.html>:
Also evaluates a polynomial at a point, but has more support for
vectorization. *First* argument is the point to evaluate at, and *second*
argument the list of coefficients *in order of increasing degree*.
Not only the order of arguments is changed between different methods, but
the order of the coefficients is reversed as well, leading to puzzling bugs
(in my experience). What could be the reason for this madness? As polyval
is a shameless ripoff of Matlab’s function of the same name
<https://www.mathworks.com/help/matlab/ref/polyval.html> anyway, why not
just use matlab’s syntax (polyval([c0, c1, c2...], x)) across the board?
 next part 
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpydiscussion/attachments/20180629/fad9ba77/attachment.html>
More information about the NumPyDiscussion
mailing list