note | Both keywords must not be used at the same time. |
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. |
; Create a 3-by-2 integer array. Each element has a value
; equal to its one-dimensional subscript.
a = INDGEN(3, 2)
PM, a
; PV-WAVE prints the following:
; 0 3
; 1 4
; 2 5
PRINT, "The sum of the elements in the first column:"
PM, TOTAL(a(*, 0))
; PV-WAVE prints: 3.00000
PRINT, "The sum of the elements in the second row:"
PM, TOTAL(a(1, *))
; PV-WAVE prints: 5.00000
PRINT, "The sum of all elements in the array:"
PM, TOTAL(a)
; PV-WAVE prints: 15.0000
PRINT, "The sum of elements across dimension 0:"
PM, TOTAL(a, Dimension=0)
; PV-WAVE prints the following:
; 3.0000 12.0000
PRINT, "The sum of elements across dimension 1:"
PM, TOTAL(a, Dimension=1)
; PV-WAVE prints:
; 3.00000
; 5.00000
; 7.00000
PRINT, "The sum of elements on the diagonal:"
PM, TOTAL(a, Dimension=[0, 1])
; PV-WAVE prints: 4.00000
a = INDGEN(4, 4) & PM, a
; PV-WAVE prints the following:
; 0 4 8 12
; 1 5 9 13
; 2 6 10 14
; 3 7 11 15
PM, TOTAL(a, Dim=0)
; PV-WAVE prints: 6.00000 22.0000 38.0000 54.0000
PM, TOTAL(a, Dim=1)
; PV-WAVE prints the following:
; 24.0000
; 28.0000
; 32.0000
; 36.0000
PM, TOTAL(a, Dim=[0,1])
; PV-WAVE prints: 30.0000
a = INDGEN(2, 2, 4) & PM, a
; PV-WAVE prints the following:
; 0 2
; 1 3
; 4 6
; 5 7
; 8 10
; 9 11
; 12 14
; 13 15
PM, TOTAL(a, Dim=2)
; PV-WAVE prints the following:
; 24.0000 32.0000
; 28.0000 36.0000
PM, TOTAL(a, Dim=[0,1])
; PV-WAVE prints the following:
; 3.00000
; 11.0000
; 19.0000
; 27.0000
a = INTARR(5, 10, 5, 10, 5)
INFO, TOTAL(a, Dim=1)
; PV-WAVE Prints: <Expression> FLOAT = Array(5, 1, 5, 10, 5)
INFO, TOTAL(a, Dim=[0,2])
; PV-WAVE Prints: <Expression> FLOAT = Array(1, 10, 1, 10, 5)