I'm trying to write a program in python which doesn't need to use extra packages like numpy and scipy. In one part of the project, if I can interpolate a function to a set of data, I can save processing time. Is there a way to fit a function to a set of data with built-in functions of python only?

  • $\begingroup$ What is your motivation to avoid using numpy and scipy? $\endgroup$
    – Anton Menshov
    Jul 23, 2018 at 23:05
  • $\begingroup$ I'm writing a package for public use, even those who don't know anything about python, so if they have to install numpy or scipy, they'll avoid using it. $\endgroup$ Jul 23, 2018 at 23:18
  • 2
    $\begingroup$ I would highly discourage you from writing those things from scratch. Installing numpy and scipy is easy. You certainly can write the interpolation yourself without using any convenient data structures or already available code from those libraries. But common problems: inefficiency, bugs, hard to support, messy code, etc. Those users will have to somehow install your package. You might want to think on how to make the installation with numpy and scipy easier rather than trying to avoid using them at all. $\endgroup$
    – Anton Menshov
    Jul 23, 2018 at 23:21

1 Answer 1


Yes a way there is. You must implement a interpolation what you do by hand when interpolate. There are different method, for example Lagrangian interpolation or Barycentric Lagrange Interpolation. This is an argument cover in all the books of numerical analysis for university level. Oblivious you will use the pit hon data structures and so on, but is possible.

Now I agree with @AntonMenshov, I do not think it is the best way. To be honest install numpy and scipy are these two lines:

pip install numpy
pip install scipy

Eventually I suggest to consider to write an your package that hide numpy and scipy and the interface/api for the final user is oriented to your specific case. Think your package as a sort of Domain Specific Language. In this way your user have got an api more near they needs, but with a strong (and more tested) back-end.

When you built your package you can indicate the dependency, you can find the python documentation, so the you lunch pip install my_package it will install the dependency indicated.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.