larray.LArray.growth_rate

LArray.growth_rate(axis=-1, d=1, label='upper')[source]

Calculates the growth along a given axis.

Roughly equivalent to a.diff(axis, d, label) / a[axis.i[:-d]]

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.

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

Examples

>>> sex = Axis('sex=M,F')
>>> year = Axis(range(2016, 2020), 'year')
>>> a = LArray([[1.0, 2.0, 3.0, 3.0], [2.0, 3.0, 1.5, 3.0]],
...            [sex, year])
>>> a
sex\year  2016  2017  2018  2019
       M   1.0   2.0   3.0   3.0
       F   2.0   3.0   1.5   3.0
>>> a.growth_rate()
sex\year  2017  2018  2019
       M   1.0   0.5   0.0
       F   0.5  -0.5   1.0
>>> a.growth_rate(d=2)
sex\year   2018  2019
       M    2.0   0.5
       F  -0.25   0.0