2

I came to know both numpy and scipy have polyfit function and visited here: http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html

Why does scipy.org have a page about numpy.polyfit? Are numpy.polyfit and scipy.polyfit the same? If not, which one should I use?

  • *"What is the difference...?"* Nothing. They are *exactly* the same object. The top-level scipy namespace includes the top-level numpy names. (I'm sure this question, or something very similar with the same answer, has been asked before.) – Warren Weckesser Jul 08 '16 at 15:07
  • *"... which one should I use?"* Use `numpy.polyfit`. More than one developer considers the dumping of the numpy names into the scipy namespace a mistake. Perhaps there were good reasons back when it was done, but now it just leads to confusion and questions like this one. – Warren Weckesser Jul 08 '16 at 15:10
  • Here's a relevant stackoverflow question: http://stackoverflow.com/questions/6200910/relationship-between-scipy-and-numpy/6201054. – Warren Weckesser Jul 08 '16 at 15:17

1 Answers1

7

polyfit is not implemented by scipy. There is a line in scipy.__init__ which does

from numpy import *

and this is how the name is pulled into scipy's namespace.

It does not make any difference which you use, because they are literally the same object in memory:

>>> import scipy
>>> import numpy
>>> scipy.polyfit is numpy.polyfit
True

You may as well cut out the middleman and use the one from numpy.

wim
  • 338,267
  • 99
  • 616
  • 750