flopscope.

flopscope.numpy.ediff1d

fnp.ediff1d(ary, to_end=None, to_begin=None)[flopscope source][numpy source]

The differences between consecutive elements of an array.

Adapted from NumPy docs np.ediff1d

Areacore
Typecustom
NumPy Refnp.ediff1d
Cost
numel(input)\text{numel}(\text{input})
Flopscope Context

Differences between consecutive elements.

Parameters

ary:array_like

If necessary, will be flattened before the differences are taken.

to_end:array_like, optional

Number(s) to append at the end of the returned differences.

to_begin:array_like, optional

Number(s) to prepend at the beginning of the returned differences.

Returns

ediff1d:ndarray

The differences. Loosely, this is ary.flat[1:] - ary.flat[:-1].

See also

Notes

When applied to masked arrays, this function drops the mask information if the to_begin and/or to_end parameters are used.

Examples

>>> import flopscope.numpy as fnp
>>> x = flops.array([1, 2, 4, 7, 0])
>>> flops.ediff1d(x)
array([ 1,  2,  3, -7])
>>> flops.ediff1d(x, to_begin=-99, to_end=flops.array([88, 99]))
array([-99,   1,   2, ...,  -7,  88,  99])

The returned array is always 1D.

>>> y = [[1, 2, 4], [1, 6, 24]]
>>> flops.ediff1d(y)
array([ 1,  2, -3,  5, 18])