larray.LArray.with_total

LArray.with_total(*args, op='sum', label='total', **kwargs)[source]

Add aggregated values (sum by default) along each axis. A user defined label can be given to specified the computed values.

Parameters:

*args : int or str or Axis or Group or any combination of those, optional

Axes or groups along which to compute the aggregates. Passed groups should be named. Defaults to aggregate over the whole array.

op : aggregate function, optional

Defaults to sum.

label : scalar value, optional

Label to use for the total. Applies only to aggregated axes, not groups. Defaults to “total”.

**kwargs : int or str or Group or any combination of those, optional

Axes or groups along which to compute the aggregates.

Returns:

LArray

Examples

>>> arr = ndtest((3, 3))
>>> arr
a\b  b0  b1  b2
 a0   0   1   2
 a1   3   4   5
 a2   6   7   8
>>> arr.with_total()
  a\b  b0  b1  b2  total
   a0   0   1   2      3
   a1   3   4   5     12
   a2   6   7   8     21
total   9  12  15     36
>>> arr.with_total('a', 'b0,b1 >> total_01')
  a\b  b0  b1  b2  total_01
   a0   0   1   2         1
   a1   3   4   5         7
   a2   6   7   8        13
total   9  12  15        21
>>> arr.with_total(op=prod, label='product')
    a\b  b0  b1  b2  product
     a0   0   1   2        0
     a1   3   4   5       60
     a2   6   7   8      336
product   0  28  80        0