Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Higher order finite differences in numpy

Tags:

python

numpy

I have sampled functions on 2D and 3D numpy arrays and I need a way to take partial derivatives from these arrays. I could code the finite difference schemes manually, but I need more than just 2nd order accuracy, probably 4th or even sixth order. With higher accuracy orders coding it manually quickly becomes tedious, especially because I need it for arrays of different dimensions.

Is there function in numpy or scipy or some other package that can do that conveniently?

like image 442
lvdhorst Avatar asked Oct 18 '25 13:10

lvdhorst


1 Answers

You may want to take a look at the findiff package. It let's you conveniently take derivatives of numpy arrays of any dimension, any derivative order and any desired accuracy order. The project website says that it features:

  • Differentiate arrays of any number of dimensions along any axis
  • Partial derivatives of any desired order
  • Standard operators from vector calculus like gradient, divergence and curl
  • Can handle uniform and non-uniform grids
  • Can handle arbitrary linear combinations of derivatives with constant and variable coefficients
  • Accuracy order can be specified
  • Fully vectorized for speed
  • Calculate raw finite difference coefficients for any order and accuracy for uniform and non-uniform grids
like image 82
owelk Avatar answered Oct 20 '25 03:10

owelk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!