Sums the elements of an inputarray.
The Dimension keyword lets you sum the elements across one or more dimensions of the input array. See the Examples sections for examples of the use of Dimension.
NOTE: If the input is of type byte, integer, or long, TOTAL performs its summation in long arithmetic. This is faster than performing the summation in floating-point arithmetic. To sum an array of longs with floating-point arithmetic, you must first convert the long values to double precision.
a = INDGEN(3, 2)
PRINT, a
0 1 2
3 4 5
PRINT, TOTAL(a(*, 0))
3.00000
.
PRINT, TOTAL(a(1, *))
5.00000
.
PRINT, TOTAL(a)
15.0000
.
PRINT, TOTAL(a, Dim=0)
3.0000
12.0000
PRINT, TOTAL(a, Dim=1)
3.00000 5.00000 7.00000
PRINT, TOTAL(a, Dim=[0,1])
4.00000
a = INDGEN( 4, 4 ) & PM, a 0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15 PM, TOTAL( a, d=0 ) 6.00000 22.0000 38.0000 54.0000 PM, TOTAL( a, d=1 ) 24.0000 28.0000 32.0000 36.0000 PM, TOTAL( a, d=[0,1] ) ; trace 30.0000 a = INDGEN( 2, 2, 4 ) & PM, a 0 2 1 3 4 6 5 7 8 10 9 11 12 14 13 15 PM, TOTAL( a, d=2 ) 24.0000 32.0000 28.0000 36.0000 PM, TOTAL( a, d=[0,1] ) 3.00000 11.0000 19.0000 27.0000 a = INTARR( 5, 10, 5, 10, 5 ) INFO, TOTAL( a, d=1 ) Expression FLOAT = Array(5, 1, 5, 10, 5) INFO, TOTAL( a, d=[0,2] ) Expression FLOAT = Array(1, 10, 1, 10, 5)