larray.Array.growth_rate

Array.growth_rate(axis=-1, d=1, label='upper') → larray.core.array.Array[source]

Calculates the growth along a given axis.

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

Parameters:
axis : int, str, Group or Axis, optional

Axis or group 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:
Array

Examples

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