Efficiently computes derivatives of NumPy code.
Maintained. Last release 5 months ago, commits in 18 of the last 26 weeks. Weaker on issue handling and release cadence.
pip install autogradAutograd

Autograd can automatically differentiate native Python and Numpy code. It can handle a large subset of Python's features, including loops, ifs, recursion and closures, and it can even take derivatives of derivatives of derivatives. It supports reverse-mode differentiation (a.k.a. backpropagation), which means it can efficiently take gradients of scalar-valued functions with respect to array-valued arguments, as well as forward-mode differentiation, and the two can be composed arbitrarily. The main intended application of Autograd is gradient-based optimization. For more information, check out the tutorial and the examples directory.
Example use:
>>> import autograd.numpy as np # Thinly-wrapped numpy
>>> from autograd import grad # The only autograd function you may ever need
>>>
>>> def tanh(x): # Define a function
... return (1.0 - np.exp((-2 * x))) / (1.0 + np.exp(-(2 * x)))
...
>>> grad_tanh = grad(tanh) # Obtain its gradient function
>>> grad_tanh(1.0) # Evaluate the gradient at x = 1.0
np.float64(0.419974341614026)
>>> (tanh(1.0001) - tanh(0.9999)) / 0.0002 # Compare to finite differences
np.float64(0.41997434264973155)
We can continue to differentiate as many times as we like, and use numpy's vectorization of scalar-valued functions across many different input values:
>>> from autograd import elementwise_grad as egrad # for functions that vectorize over inputs
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(-7, 7, 700)
>>> plt.plot(x, tanh(x),
... x, egrad(tanh)(x), # first derivative
... x, egrad(egrad(tanh))(x), # second derivative
... x, egrad(egrad(egrad(tanh)))(x), # third derivative
... x, egrad(egrad(egrad(egrad(tanh))))(x),) # fourth derivative
>>> plt.show()

