# ndarray-gradient

> Finds the gradient of an ndarray using finite differences

Latest version **1.0.1** (published 2021-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install ndarray-gradient
pnpm add ndarray-gradient
yarn add ndarray-gradient
bun add ndarray-gradient
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-09-03 |
| First published | 2014-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko, jaspervdg, hughsk, substack, planeshifter, rreusser |
| Keywords | gradient, ndarray, finite, difference |

## Links

- npm: https://www.npmjs.com/package/ndarray-gradient
- Repository: https://github.com/mikolalysenko/ndarray-gradient
- Issues: https://github.com/mikolalysenko/ndarray-gradient/issues
- npm.io page: https://npm.io/package/ndarray-gradient

## Dependencies (2)

- [dup](https://npm.io/package/dup.md) ^1.0.0
- [cwise-compiler](https://npm.io/package/cwise-compiler.md) ^1.0.0

## Recent versions

- 1.0.1 (latest) — 2021-09-03
- 1.0.0 — 2014-10-04

## README

ndarray-gradient
================
Computes the gradient of an ndarray using a 2-point central finite difference template.

# Example

```javascript
var pack = require('ndarray-pack')
var pool = require('ndarray-scratch')
var grad = require('ndarray-gradient')
var show = require('ndarray-show')

var X = pack([[0, 0, 0],
              [0, 1, 0],
              [0, 0, 0]])

//Compute gradient of X
var dX = grad(pool.zero([3,3,2]), X)

console.log('grad(X) = \n', show(dX))
```

Output:

```
grad(X) =
   0.000    0.000    0.000
  -0.500    0.000    0.500
   0.000    0.000    0.000

   0.000   -0.500    0.000
   0.000    0.000    0.000
   0.000    0.500    0.000
```

# Install

```
npm install ndarray-gradient
```

# API

### `require('ndarray-gradient')(dst, src[, bc])`
Computes the gradient of `src` storing the result into `dst`.

* `dst` is an array of gradient values.  The shape of `dst` must be the shape of `src` with one additional dimension for the components of the gradient
* `src` is the array to differentiate
* `bc` is an array of boundary conditions.  The boundary conditions are encoded as string values and must be one of the following values:

    + `'clamp'` (Default) clamp boundary edges to boundary
    + `'mirror'` mirror values across the boundary
    + `'wrap'` wrap values across boundary

**Returns** `dst`

# Credits
(c) 2014 Mikola Lysenko. MIT License

---
_Source: https://npm.io/package/ndarray-gradient · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
