CUMSUM Function

Computes the cumulative sum over an array or over one dimension of an array.

enabled.

Usage

    result = CUMSUM(array)

Input Parameters

array—An array of any real data-type.

Returned Value

result—An array of the same dimensions as the input array. If the input is of type BYTE or short-integer then the result is of type INT32, otherwise it is of the same type as the input. Computation is performed in the data type of the result.

Keywords

Dimension—A scalar (n ≥ 0) that specifies the dimension over which to operate.

Discussion

The cumulative sum s of an array b is defined recursively:

    s(0) = b(0)

    s(i) = s(i-1) + b(i)

By default, CUMSUM computes the cumulative sum of an array, without regard to dimensionality, i.e., as if it were 1D. The Dimension keyword allows cumulative sums to be computed for each vector along one dimension of an array, most commonly along the columns or rows of a matrix.

Example

The following three examples use CUMSUM to find the cumulative sum of a matrix, to find the cumulative sum of each column in a matrix, and to find the cumulative sum of each row in a matrix.

a = INDGEN(3, 4) 
PM, a
; PV-WAVE prints the following:
; 0       3       6       9
; 1       4       7      10
; 2       5       8      11
PM, CUMSUM(a)
; PV-WAVE prints the following:
; 0           6          21          45
; 1          10          28          55
; 3          15          36          66
PM, CUMSUM(a, Dimension=0)
; PV-WAVE prints the following:
; 0           3           6           9
; 1           7          13          19
; 3          12          21          30
PM, CUMSUM(a, Dimension=1)
; PV-WAVE prints the following:
; 0           3           9          18
; 1           5          12          22
; 2           7          15          26

See Also

TOTAL, SIZE