SUM Function
Sums an array of n dimensions over one of its dimensions.
Usage
result = SUM (array, dim)
Input Parameters
array—An array of n dimensions of any data type except string.
dim—The dimension over which array is summed. The dim parameter must be a number in the range 0 £ dim £ (n–1), where n is the number of dimensions in array.
Returned Value
result—A scalar value equal to the sum of the array elements over the specified dimension.
Keywords
None.
Discussion
If array is either a single or double-precision complex, or a double-precision floating-point data type, the result is of the same data type. SUM returns a single-precision floating-point value for all other acceptable data types.
Example
This example illustrates SUM being used for a variety of arrays of different sizes.
; Create two arrays, array1, a one-dimensional array with two ; elements and array2, a two-dimensional array with four ; elements, using FINDGEN. array1 = FINDGEN(2) array2 = FINDGEN(2,2) ; Print the arrays then sum each array over each of its dimensions ; and print the result. PRINT, array1 ; PV-WAVE prints: 0.00000 1.00000 PRINT, array2 ; PV-WAVE prints the following: ; 0.00000 1.00000 ; 2.00000 3.00000 PRINT, SUM(array1, 0) ; PV-WAVE prints: 1.00000 PRINT, SUM(array2, 0) ; PV-WAVE prints: 1.00000 5.00000 PRINT, SUM(array2, 1) ; PV-WAVE prints: 2.00000 4.00000