PRODUCT(ARRAY, DIM, MASK) or PRODUCT(ARRAY, MASK)

Purpose

Multiplies together all elements in an entire array, or selected elements from all vectors in a specified dimension of an array.

Class

Transformational function

Argument type and attributes

ARRAY
An array with a numeric data type.
DIM (optional)
An INTEGER scalar (a specified dimension of ARRAY). Its value must be in the range 1 ≤ DIM ≤ rank(ARRAY).
MASK (optional)
A LOGICAL expression that conforms with ARRAY in shape. If MASK is a scalar, the scalar value applies to all elements in ARRAY.

Result value

If DIM is present, the result is an array of rank rank(ARRAY)-1 and the same data type and kind type parameter as ARRAY. If DIM is missing, or if MASK has a rank of one, the result is a scalar.

The result is calculated by one of the following methods:
Method 1:
If only ARRAY is specified, the result is the product of all its array elements. If ARRAY is a zero-sized array, the result is equal to one.
Method 2:
If ARRAY and MASK are both specified, the result is the product of those array elements of ARRAY that have a corresponding true array element in MASK. If MASK has no elements with a value of .TRUE., the result is equal to one.
Method 3:
If DIM is also specified and ARRAY has a rank of one, the result is a scalar equal to the product of all elements of ARRAY that have a corresponding .TRUE. array element in MASK.

If DIM is also specified and ARRAY has rank greater than one, the result is a new array in which dimension DIM has been eliminated. Each new array element is the product of elements from a corresponding vector within ARRAY. The index values of that vector, in all dimensions except DIM, match those of the output element. The output element is the product of those vector elements that have a corresponding .TRUE. array element in MASK.

Because both DIM and MASK are optional, various combinations of arguments are possible. When the -qintlog option is specified with two arguments, the second argument refers to one of the following:
  • MASK if it is an array of type integer, logical, byte or typeless
  • DIM if it is a scalar of type integer, byte or typeless
  • MASK if it is a scalar of type logical

Examples