larray.Array.growth_rate
- Array.growth_rate(axis=-1, d=1, label='upper') Array [source]
Compute 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
- Array
Examples
>>> data = [[4, 5, 4, 6, 9], [2, 4, 3, 0, 0]] >>> a = Array(data, "sex=F,M; year=2017..2021") >>> a sex\year 2017 2018 2019 2020 2021 F 4 5 4 6 9 M 2 4 3 0 0 >>> a.growth_rate() sex\year 2018 2019 2020 2021 F 0.25 -0.2 0.5 0.5 M 1.0 -0.25 -1.0 0.0 >>> a.growth_rate(label='lower') sex\year 2017 2018 2019 2020 F 0.25 -0.2 0.5 0.5 M 1.0 -0.25 -1.0 0.0 >>> a.growth_rate(d=2) sex\year 2019 2020 2021 F 0.0 0.2 1.25 M 0.5 -1.0 -1.0
It works on any axis, not just time-based axes
>>> a.growth_rate('sex') sex\year 2017 2018 2019 2020 2021 M -0.5 -0.2 -0.25 -1.0 -1.0
Or part of axes
>>> a.growth_rate(a.year[2017:]) sex\year 2018 2019 2020 2021 F 0.25 -0.2 0.5 0.5 M 1.0 -0.25 -1.0 0.0