pytaco.tensor_sum

pytaco.tensor_sum(t1, axis=None, out_format=mode_format(compressed), dtype=None)

Sums a tensor along a specified axis or axes of a tensor.

Parameters
t1: tensor, array_like

The elements to sum.

axis: None, int or tuple of ints, optional

Axis or axes along which the sum is performed. If the axis is a tuple of ints, the sum is performed on all of the specified axes.

out_format: format, mode_format, optional
  • If a format is specified, the result tensor is stored in the format out_format.

  • If a mode_format is specified, the result the result tensor has a with all of the dimensions stored in the mode_format passed in.

dtype: Datatype

The datatype of the output tensor.

Returns
summed_axes: tensor

A tensor with the same dimensions as t1 with all of the specified axes removed. If axis is None, a scalar tensor is returned.

Examples

The sum of an empty element is 0.

>>> import pytaco as pt
>>> pt.tensor_sum([])[0]
0.0
>>> pt.tensor_sum([0.5, 1.5])[0]
2.0
>>> pt.tensor_sum([0.5, 0.7, 0.2, 1.5], dtype=pt.int32)[0]
1
>>> pt.tensor_sum([[0, 1], [0, 5]])[0]
6
>>> pt.tensor_sum([[0, 1], [0, 5]], axis=0).to_array()
array([0, 6], dtype=int64)
>>> pt.tensor_sum([[0, 1], [0, 5]], axis=1).to_array()
array([1, 5], dtype=int64)