larray.Array.diff
- Array.diff(axis=-1, d=1, n=1, label='upper') Array [source]
Compute 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
- axisint, str, Group or Axis, optional
Axis or group along which the difference is taken. Defaults to the last axis.
- dint, optional
Periods to shift for forming difference. Defaults to 1.
- nint, 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
- Array
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 = ndtest('sex=M,F;type=type1,type2,type3').cumsum('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('sex') sex\type type1 type2 type3 F 3 6 9 >>> a.diff(a.type['type2':]) sex\type type3 M 2 F 5