All I'm looking for is a Python library that contains functionality to compute (possibly via finite differences) the numerical derivative of a 2D array (list of 2D points (x, y); I want dy/dx) to an arbitrary order of accuracy, i.e. by taking into account an arbitrary number of data points (see, for instance, Wikipedia: Finite difference coefficient).

There is numpy.gradient, but it only does second order accuracy.

There are loads of libraries that do the trick for functions instead of arrays (via automatic differentiation (AD) or by evaluating the function repeatedly and applying finite differences), but I don't know if they work well for discrete 2D data, and wrapping my data in a function just to accomplish this simple task seems very inelegant anyway.

Maybe I'm missing something very obvious, but I'm quite frustrated because this seems like such a simple and common task, yet I can't find a single library that does it. Is it not cool enough for people to publish their implementations? (That would explain why there are dozens of AD libraries, which is a bit harder to code.) Or do people normally smoothen their data beforehand, until lower-order differentiation produces useful results?

  • do you want the derivatives at each point?
    – costrom
    Commented Apr 14, 2016 at 17:29
  • @costrom yes. Maybe the ones at the edges can be left out, though.
    – smheidrich
    Commented Apr 15, 2016 at 16:23
  • 1
    I am unaware of any software that does arbitrary order finite differencing like this. if the data is set up as two nx by ny matrices, you can write some code to generate arbitrary stencils and find the finite difference approximations pretty quickly...
    – costrom
    Commented Apr 15, 2016 at 17:10

1 Answer 1


There are a number of methods, with different names, in the pandas library - I would take a look at the various rolling methods in the documentation.

  • Couldn't find anything there, sorry.
    – smheidrich
    Commented Apr 17, 2015 at 8:08

Your Answer

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

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