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?