# cumsum

``````..  cumsum(A, [dim])

Cumulative sum along a dimension ``dim`` (defaults to 1).
both for performance and to control the precision of the
output (e.g. to avoid overflow).``````

## Examples

The `cumsum` function in Julia calculates the cumulative sum along a specified dimension of an array. The default dimension is 1. Here are some examples of its usage:

1. Cumulative sum of a 1-dimensional array:

``````julia> A = [1, 2, 3, 4, 5];
julia> cumsum(A)
5-element Array{Int64,1}:
1
3
6
10
15``````

This example calculates the cumulative sum of the elements in the array `A` along dimension 1.

2. Cumulative sum of a 2-dimensional array along a specified dimension:

``````julia> A = [1 2 3; 4 5 6; 7 8 9];
julia> cumsum(A, 2)
3×3 Array{Int64,2}:
1   3   6
4   9  15
7  15  24``````

It calculates the cumulative sum along dimension 2 of the 2-dimensional array `A`.

3. Cumulative sum of a vector of floating-point numbers:
``````julia> A = [1.2, 2.3, 3.4, 4.5];
julia> cumsum(A)
4-element Array{Float64,1}:
1.2
3.5
6.9
11.4``````

This example demonstrates the cumulative sum calculation on a vector of floating-point numbers.

It is worth mentioning the `cumsum!` function, which can be used to perform the cumulative sum operation in-place for improved performance and control over precision.