The MATRIX_MULTIPLY function calculates the IDL # operator of two (possibly transposed) arrays. The transpose operation (if desired) is done simultaneously with the multiplication, thus conserving memory and increasing the speed of the operation. If the arrays are not transposed, then MATRIX_MULTIPLY is equivalent to using the # operator.

### The # Operator vs. MATRIX_MULTIPLY

The following table illustrates how various operations are performed using the # operator versus the MATRIX_MULTIPLY function:

 # Operator Function A # B matrix_multiply(A, B) transpose(A) # B matrix_multiply(A, B, /ATRANSPOSE) A # transpose(B) matrix_multiply(A, B, /BTRANSPOSE) transpose(A) # transpose(B) matrix_multiply(A, B, /ATRANSPOSE, /BTRANSPOSE)

Note: MATRIX_MULTIPLY can also be used in place of the ## operator. For example, A ## B is equivalent to MATRIX_MULTIPLY(B, A), and A ## TRANSPOSE(B) is equivalent to MATRIX_MULTIPLY(BA, /ATRANSPOSE).

Note: MATRIX_MULTIPLY will invoke BLAS_GEMM for floating-point and complex inputs.

## Syntax

Result = MATRIX_MULTIPLY( A, B [, /ATRANSPOSE] [, /BTRANSPOSE] [, /NAN])

## Return Value

The type for the result depends upon the input type. For byte or integer arrays, the result has the type of the next-larger integer type that could contain the result (for example, byte, integer, or long input returns type long integer). For floating-point, the result has the same type as the input.

For the case of no transpose, the resulting array has the same number of columns as the first array and the same number of rows as the second array. The second array must have the same number of columns as the first array has rows.

Note: If A and B arguments are vectors, then C = MATRIX_MULTIPLY(A, B) is a matrix with Cij = AiBj. Mathematically, this is equivalent to the outer product, usually denoted by AÄB.

## Arguments

### A

The left operand for the matrix multiplication. Dimensions higher than two are ignored.

### B

The right operand for the matrix multiplication. Dimensions higher than two are ignored.

## Keywords

### ATRANSPOSE

Set this keyword to multiply using the transpose of A.

### BTRANSPOSE

Set this keyword to multiply using the transpose of B.

### NAN

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 equal to zero.