larray.LArray.diff¶
-
LArray.diff(axis=-1, d=1, n=1, label='upper')[source]¶ Calculates the n-th order discrete difference along a given axis.
The first order difference is given by out[n] = a[n + 1] - a[n] along the given axis, higher order differences are calculated by using diff recursively.
Parameters: axis : int, str or Axis, optional
Axis along which the difference is taken. Defaults to the last axis.
d : int, optional
Periods to shift for forming difference. Defaults to 1.
n : int, optional
The number of times values are differenced. Defaults to 1.
label : {‘lower’, ‘upper’}, optional
The new labels in axis will have the labels of either the array being subtracted (‘lower’) or the array it is subtracted from (‘upper’). Defaults to ‘upper’.
Returns: LArray :
The n-th order differences. The shape of the output is the same as a except for axis which is smaller by n * d.
Examples
>>> a = ndrange('sex=M,F;type=type1,type2,type3').cumsum(X.type) >>> a sex\type type1 type2 type3 M 0 1 3 F 3 7 12 >>> a.diff() sex\type type2 type3 M 1 2 F 4 5 >>> a.diff(n=2) sex\type type3 M 1 F 1 >>> a.diff(X.sex) sex\type type1 type2 type3 F 3 6 9