larray.LArray.rationot0

LArray.rationot0(self, *axes)[source]

Returns a LArray with values array / array.sum(axes) where the sum is not 0, 0 otherwise.

Parameters
*axes
Returns
LArray

array / array.sum(axes)

Examples

>>> a = Axis('a=a0,a1')
>>> b = Axis('b=b0,b1,b2')
>>> arr = LArray([[6, 0, 2],
...               [4, 0, 8]], [a, b])
>>> arr
a\b  b0  b1  b2
 a0   6   0   2
 a1   4   0   8
>>> arr.sum()
20
>>> arr.rationot0()
a\b   b0   b1   b2
 a0  0.3  0.0  0.1
 a1  0.2  0.0  0.4
>>> arr.rationot0('a')
a\b   b0   b1   b2
 a0  0.6  0.0  0.2
 a1  0.4  0.0  0.8

for reference, the normal ratio method would return:

>>> arr.ratio('a')
a\b   b0   b1   b2
 a0  0.6  nan  0.2
 a1  0.4  nan  0.8