New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

numgrad

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

numgrad

Simple gradient computation library in Python

  • 0.3.0
  • PyPI
  • Socket score

Maintainers
1

NumGrad

Simple gradient computation library for Python.

Getting Started

pip install numgrad

Inspired by tensorflow, numgrad supports automatic differentiation in tensorflow v2 style using original numpy and scipy functions.

>>> import numgrad as ng
>>> import numpy as np  # Original numpy
>>>
>>> # Pure numpy function
>>> def tanh(x):
...     y = np.exp(-2 * x)
...     return (1 - y) / (1 + y)
...
>>> x = ng.Variable(1)
>>> with ng.Graph() as g:
...     # numgrad patches numpy functions automatically here
...     y = tanh(x)
...
>>> g.backward(y, [x])
(0.419974341614026,)
>>> (tanh(1.0001) - tanh(0.9999)) / 0.0002
0.41997434264973155

numgrad also supports jax style automatic differentiation.

>>> import numgrad as ng
>>> import numpy as np  # Original numpy unlike `jax`
>>>
>>> power_derivatives = [lambda a: np.power(a, 5)]
>>> for _ in range(6):
...     power_derivatives.append(ng.grad(power_derivatives[-1]))
...
>>> [f(2) for f in power_derivatives]
[32, 80.0, 160.0, 240.0, 240.0, 120.0, 0.0]
>>> [f(-1) for f in power_derivatives]
[-1, 5.0, -20.0, 60.0, -120.0, 120.0, -0.0]

Contribute

Be sure to run the following command before developing

$ git clone https://github.com/ctgk/numgrad.git
$ cd numgrad
$ pre-commit install

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc