sum

Graph.sum(input_tensor, axis=None, keepdims=False, *, name=None)

Returns the sum of all the elements in a tensor (or a list of tensors with the same shape), or the sum of a tensor along one or multiple axes.

Parameters
  • input_tensor (np.ndarray or Tensor or list[Tensor]) – The tensor whose elements you want to sum. If you pass a list of tensors, they must all have the same shape, and are interpreted as being stacked along a new first dimension (for example, if you pass two 2D tensors of shape [3, 4], the result is equivalent to passing the stacked 3D tensor of shape [2, 3, 4]).

  • axis (int or list[int] or tuple[int], optional) – The dimension or dimensions along which you want to sum the tensor. Defaults to None, in which case this node sums along all axes of the tensor.

  • keepdims (bool, optional) – Whether or not to retain summed axes in the output tensor. If true, each dimension in axis has size 1 in the result; otherwise, the dimensions in axis are removed from the result. Defaults to false.

  • name (str, optional) – The name of the node.

Returns

The tensor obtained by summing the input tensor along the specified axes (or, if axis was None, the tensor obtained by summing the input tensor along all of the specified axes).

Return type

Tensor

See also

einsum()

Tensor contraction via Einstein summation convention.