ndarray-gradient
Computes the gradient of an ndarray using a 2-point central finite difference template.
Example
var pack = var pool = var grad = var show = var X = //Compute gradient of Xvar dX = console
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 ofdst
must be the shape ofsrc
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