The PRODUCT function returns the product of elements within an array. The product of the array elements over a given dimension is returned if the Dimension argument is present. Because the product can easily overflow, the product is computed using double-precision arithmetic and the Result is double precision.
Result = PRODUCT(Array [, Dimension] [, /CUMULATIVE] [, /INTEGER] [, /NAN] [, /PRESERVE_TYPE] )
Returns the product of the elements of Array.
The array for which to compute the product. This array can be of any basic type except string.
An optional argument specifying the dimension over which to compute the product, starting at one. If this argument is not present or zero, the product of all the array elements is returned. If this argument is present, the result is an array with one less dimension than Array. For example, if the dimensions of Array are N1, N2, N3, and Dimension is 2, the dimensions of the result are (N1, N3), and element (i,j) of the result contains the product:
If this keyword is set, the result is an array of the same size as the input, with each element, i, containing the product of the input array elements 0 to i. This keyword also works with the Dimension parameter, in which case the cumulative product is performed over the given dimension.
Set this keyword to perform the PRODUCT using integer arithmetic, and to return an integer result. If Array is of type ULONG64 then unsigned 64-bit integers are used for the computation and the Result is of type ULONG64, otherwise signed 64-bit integers are used and the Result is of type LONG64. If Array is complex and INTEGER is set, then only the real part of each value is used for the computation.
Set this keyword to cause the routine to check for occurrences of the IEEE floating-point values NaN or Infinity in the input data. Elements with the value NaN or Infinity are treated as missing data. Elements with the value NaN are treated as missing data with the value 1. (See Special Floating-Point Values for more information on IEEE floating-point values.)
Set this keyword to perform the PRODUCT using the input type, and to return a result of the same type. The INTEGER keyword is ignored if PRESERVE_TYPE is set.
This routine is written to make use of IDL's thread pool, which can increase execution speed on systems with multiple CPUs. The values stored in the
To find the product of all elements in a one-dimensional array:
; Define a one-dimensional array: array = [20, 10, 5, 5, 3] ; Find the product of the array elements: prod = PRODUCT(array) ; Print the results: PRINT, 'Product of Array = ', prod
Product of Array = 15000.000
Now find the product of elements in a two-dimensional array:
; Define a two-dimensional array: array = FINDGEN(4,4) + 1 ; Find the product of all array elements: prodAll = PRODUCT(array) ; Find the product along the first dimension: prod1 = PRODUCT(array, 1) ; Find the product along the second dimension: prod2 = PRODUCT(array, 2) ; Print the results: PRINT, 'Product of all elements = ', prodAll PRINT, 'Product along first dimension: ' PRINT, prod1 PRINT, 'Product along second dimension: ' PRINT, prod2
Product of all elements 2.0922790e+013 Product along first dimension: 24.000000 1680.0000 11880.000 43680.000 Product along second dimension: 585.00000 1680.0000 3465.0000 6144.0000
INTEGER and PRESERVE_TYPE keywords: 6.1