larray.Array.ratio

Array.ratio(*axes) Array[source]

Return an array with all values divided by the sum of values along given axes.

Parameters
*axes
Returns
Array

array / array.sum(axes)

Examples

>>> nat = Axis('nat=BE,FO')
>>> sex = Axis('sex=M,F')
>>> a = Array([[4, 6], [2, 8]], [nat, sex])
>>> a
nat\sex  M  F
     BE  4  6
     FO  2  8
>>> a.sum()
20
>>> a.ratio()
nat\sex    M    F
     BE  0.2  0.3
     FO  0.1  0.4
>>> a.ratio('sex')
nat\sex    M    F
     BE  0.4  0.6
     FO  0.2  0.8
>>> a.ratio('M')
nat\sex    M    F
     BE  1.0  1.5
     FO  1.0  4.0