dpnp.tensor.cumulative_sum

dpnp.tensor.cumulative_sum(x, /, *, axis=None, dtype=None, include_initial=False, out=None)[source]

Calculates the cumulative sum of elements in the input array x.

Parameters:
  • x (usm_ndarray) -- input array.

  • axis ({None, int}, optional) --

    axis along which cumulative sum must be computed. If None, the sum is computed over the entire array. If x is a one-dimensional array, providing an axis is optional; however, if x has more than one dimension, providing an axis is required.

    Default: None.

  • dtype ({None, dtype}, optional) --

    data type of the returned array. If None, the default data type is inferred from the "kind" of the input array data type.

    • If x has a real- or complex-valued floating-point data type, the returned array will have the same data type as x.

    • If x has signed integral data type, the returned array will have the default signed integral type for the device where input array x is allocated.

    • If x has unsigned integral data type, the returned array will have the default unsigned integral type for the device where input array x is allocated.

    • If x has a boolean data type, the returned array will have the default signed integral type for the device where input array x is allocated.

    If the data type (either specified or resolved) differs from the data type of x, the input array elements are cast to the specified data type before computing the cumulative sum.

    Default: None.

  • include_initial (bool, optional) --

    boolean indicating whether to include the initial value (i.e., the additive identity, zero) as the first value along the provided axis in the output.

    Default: False.

  • out ({None, usm_ndarray}, optional) --

    the array into which the result is written. The data type of out must match the expected shape and the expected data type of the result or (if provided) dtype. If None then a new array is returned.

    Default: None.

Returns:

out -- an array containing cumulative sums. The returned array has the data type as described in the dtype parameter description above.

The returned array shape is determined as follows:

  • If include_initial is False, the returned array will have the same shape as x

  • If include_initial is True, the returned array will have the same shape as x except the axis along which the cumulative sum is calculated, which will have size N+1

where N is the size of the axis the cumulative sums are computed along.

Return type:

usm_ndarray