cumulative_sum

Graph.cumulative_sum(x, axis=0, *, name=None)

Calculate the cumulative sum of a tensor along a specified dimension.

Parameters

  • x (np.ndarray or Tensor) – The tensor whose elements you want to sum. It must have at least one dimension.
  • axis (int , optional) – The dimension along which you want to sum the tensor. Defaults to 0.
  • name (str or None , optional) – The name of the node.

Returns

The cumulative sum of x along dimension axis.

Return type

Tensor

Examples

>>> x = np.array([1, 2, 3])
>>> y = np.array([[1, 2, 3], [4, 5, 6]])

Calculate the cumulative sum of an array.

>>> graph.cumulative_sum(x, axis=0, name="a")
<Tensor: name="a", operation_name="cumulative_sum", shape=(3,)>
>>> result = bo.execute_graph(graph=graph, output_node_names="a")
>>> result["output"]["a"]["value"]
array([1, 3, 6])

Calculate the cumulative sum of a 2D array along its first dimension.

>>> graph.cumulative_sum(y, axis=0, name="b")
<Tensor: name="b", operation_name="cumulative_sum", shape=(2, 3)>
>>> result = bo.execute_graph(graph=graph, output_node_names="b")
>>> result["output"]["b"]["value"]
array([[1, 2, 3],
       [5, 7, 9]])

Calculate the cumulative sum of a 2D array along its second dimension.

>>> graph.cumulative_sum(y, axis=1, name="c")
<Tensor: name="c", operation_name="cumulative_sum", shape=(2, 3)>
>>> result = bo.execute_graph(graph=graph, output_node_names="c")
>>> result["output"]["c"]["value"]
array([[ 1,  3,  6],
       [ 4,  9, 15]])

Was this useful?