Skip to content

numpy.polynomial.polynomial.polyfit and numpy.polyfit return coefficients in different order #11732

@astrofrog

Description

@astrofrog

Summary

This may be a 'historical reasons' issue, but it looks like numpy.polynomial.polynomial.polyfit and numpy.polyfit return coefficients in reverse order from each other. I wonder if one of the functions should be deprecated from the public API in future, as having two functions with the same name in the same package that operate differently can lead to confusion?

Reproducing code example:

import numpy as np
from numpy.polynomial.polynomial import polyfit

x = np.linspace(0, 1, 100)
y = x ** 3

p1 = np.polyfit(x, y, 3)
p2 = polyfit(x, y, 3)

print('p1', p1)
print('p2', p2)

Result

p1 [ 1.00000000e+00  4.64782291e-16 -7.05817953e-16 -1.47054969e-17]
p2 [-1.93895090e-16  8.46391197e-16 -7.28660556e-16  1.00000000e+00]

Numpy/Python version information:

Python 3.6, Numpy 1.15.0, installed with conda.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions