Autograd

1.8.0 · active · verified Thu Apr 09

Autograd is a Python library that efficiently computes derivatives of native Python and NumPy code using automatic differentiation. The current version, 1.8.0, supports Python 3.9-3.13 and has a release cadence that includes compatibility updates for new Python and NumPy versions, along with bug fixes and minor features.

Warnings

Install

Imports

Quickstart

This example defines a simple tanh function using `autograd.numpy`, then uses `autograd.grad` to obtain its derivative function. The gradient is then evaluated at a specific point.

import autograd.numpy as np
from autograd import grad

def tanh(x):
    return (1.0 - np.exp((-2 * x))) / (1.0 + np.exp(-(2 * x)))

grad_tanh = grad(tanh)
x_val = np.float64(1.0)

print(f"tanh({x_val}) = {tanh(x_val)}")
print(f"Gradient of tanh at {x_val} = {grad_tanh(x_val)}")

view raw JSON →