The PRODUCT function returns the product of elements of an array expression, along a given dimension, or under the control of a logical mask.

## Syntax

PRODUCT (array [,dim] [,mask])

*array* is an INTENT(IN) array of type INTEGER, REAL or COMPLEX.

*dim* is an INTENT(IN) scalar INTEGER in the range *dim* ≤ *n**n* is the rank of *array*. The corresponding actual argument must not be an optional dummy argument.

*mask* is INTENT(IN), must be of type LOGICAL, and must be conformable with *array*.

The result is of the same type and kind as *array*.

It is scalar if *dim* is absent or if *array* has rank one; otherwise the result is an array of rank n-1 and of shape (*d _{1},d_{2}, ...,d_{dim-1},d_{dim+1}, ...,d_{n}*) where (

If *dim* is absent, the result is the product of all the elements of *array*.

If *dim* is present, the result is the product of all elements of *array* along dimension *dim*.

If *mask* is present, the result is the product of all elements of *array* for which *mask* evaluates to true.

## Example

integer,dimension(2,2) :: m=reshape((/1,2,3,4/),shape(m)) write(*,'2i3)') m ! writes 1 2 ! 3 4 write(*,*) product(m) ! writes 24 write(*,*) product(m,dim=1) ! writes 2 12 write(*,*) product(m,dim=2) ! writes 3 8 write(*,*) product(m,mask=m>2) ! writes 12 write(*,*) product(m,dim=1,mask=m>2) ! writes 1 12 write(*,*) product(m,dim=2,mask=m>2) ! writes 3 4