larray.LArray.growth_rate

LArray.growth_rate(self, 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
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.

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

>>> data = [[2, 4, 5, 4, 6], [4, 6, 3, 6, 9]]
>>> a = LArray(data, "sex=M,F; year=2016..2020")
>>> a
sex\year  2016  2017  2018  2019  2020
       M     2     4     5     4     6
       F     4     6     3     6     9
>>> a.growth_rate()
sex\year  2017  2018  2019  2020
       M   1.0  0.25  -0.2   0.5
       F   0.5  -0.5   1.0   0.5
>>> a.growth_rate(label='lower')
sex\year  2016  2017  2018  2019
       M   1.0  0.25  -0.2   0.5
       F   0.5  -0.5   1.0   0.5
>>> a.growth_rate(d=2)
sex\year   2018  2019  2020
       M    1.5   0.0   0.2
       F  -0.25   0.0   2.0
>>> a.growth_rate('sex')
sex\year  2016  2017  2018  2019  2020
       F   1.0   0.5  -0.4   0.5   0.5
>>> a.growth_rate(a.year[2017:])
sex\year  2018  2019  2020
       M  0.25  -0.2   0.5
       F  -0.5   1.0   0.5