Skip to main content
https://badge.fury.io/py/numdifftools.png https://travis-ci.org/pbrod/numdifftools.svg?branch=master https://pypip.in/d/numdifftools/badge.png

Suite of tools written in Python to solve automatic numerical differentiation problems in one or more variables. Finite differences are used in an adaptive manner, coupled with a Romberg extrapolation methodology to provide a maximally accurate result. The user can configure many options like; changing the order of the method or the extrapolation, even allowing the user to specify whether central, forward or backward differences are used. The methods provided are:

Derivative: Compute the derivatives of order 1 through 4 on any scalar function.

Gradient: Compute the gradient vector of a scalar function of one or more variables.

Jacobian: Compute the Jacobian matrix of a vector valued function of one or more variables.

Hessian: Compute the Hessian matrix of all 2nd partial derivatives of a scalar function of one or more variables.

Hessdiag: Compute only the diagonal elements of the Hessian matrix

All of these methods also produce error estimates on the result. The documentation for these tools are given at http://numdifftools.readthedocs.org.

To test if the toolbox is working paste the following in an interactive python session:

import numdifftools as nd
nd.test(coverage=True, doctests=True)

Examples

Compute 1’st and 2’nd derivative of exp(x), at x == 1:

>>> import numpy as np
>>> import numdifftools as nd
>>> fd = nd.Derivative(np.exp)              # 1'st derivative
>>> fdd = nd.Derivative(np.exp, n=2)  # 2'nd derivative
>>> fd(1)
array([ 2.71828183])

Nonlinear least squares:

>>> xdata = np.reshape(np.arange(0,1,0.1),(-1,1))
>>> ydata = 1+2*np.exp(0.75*xdata)
>>> fun = lambda c: (c[0]+c[1]*np.exp(c[2]*xdata) - ydata)**2
>>> Jfun = nd.Jacobian(fun)
>>> np.abs(Jfun([1,2,0.75])) < 1e-14 # should be numerically zero
array([[ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True],
       [ True,  True,  True]], dtype=bool)

Compute gradient of sum(x**2):

>>> fun = lambda x: np.sum(x**2)
>>> dfun = nd.Gradient(fun)
>>> dfun([1,2,3])
array([ 2.,  4.,  6.])

See also

scipy.misc.derivative

Release files for numdifftools 0.7.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for numdifftools 0.7.7
File Size Uploaded
numdifftools-0.7.7.zip 181.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for numdifftools 0.7.7
File Interpreter ABI Platform
numdifftools-0.7.7.win32.exe Details

Total release size: 404.6 kB

Release files / numdifftools-0.7.7.zip

Download URL numdifftools-0.7.7.zip
Size 181.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c5a309a7a0b58f6177dc7e3d55c2830c07ca2715c9c706644d500fc4eca97c4d
BLAKE2b-256 checksum
How to use checksums
ea1e4006e7e8e6b5cae2d42657ab31de2474dca3daa6e06df17a36ae45932e52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / numdifftools-0.7.7.win32.exe

Download URL numdifftools-0.7.7.win32.exe
Size 223.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2a9fa00e33a3d5ff8576f017c5e7abafdc51278ad88861e1b9640c7ccf5e1d99
BLAKE2b-256 checksum
How to use checksums
991b7e02c71baeb64f3c09252ef1ee2d939d76f7dee310d01ee416d06db5b32a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.10.1

2 release files

0.9.42

2 release files

0.9.41

2 release files

0.9.39

2 release files

0.9.38

2 release files

0.9.20

2 release files

0.9.16

1 release file

0.9.15

1 release file

0.9.14

2 release files

0.9.13

2 release files

0.9.12

2 release files

0.9.11

0.9.10

2 release files

0.9.2

2 release files

This release

0.7.7 This release

2 release files

0.7.3

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.1

2 release files

0.2.1

2 release files

0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page