Language > Operators > Matrix Operators

# Matrix Operators

IDL has two operators used to multiply arrays and matrices. For an example illustrating the difference between the two, see Multiplying Arrays.

If one or both of the operands are objects, the operator may be overloaded.

Operator | Description | Example
# | Computes array elements by multiplying the columns of the first array by the rows of the second array. The second array must have the same number of columns as the first array has rows. The resulting array has the same number of columns as the first array and the same number of rows as the second array. | Multiply a 3-column by 2-row array: array1 = [ [1, 2, 1], $ [2, -1, 2] ] Create a 2-column by 3-row array: array2 = [ [1, 3], [0, 1],$ [1, 1] ] PRINT, array1#array2 IDL prints: 7 -1 7 2 -1 2 3 1 3
## | Computes array elements by multiplying the rows of the first array by the columns of the second array. The second array must have the same number of rows as the first array has columns. The resulting array has the same number of rows as the first array and the same number of columns as the second array. | Create a 3-column by 2-row array: array1 = [ [1, 2, 1], [2, -1, 2] ] Create a 2-column by 3-row array: array2 = [[1, 3], [0, 1], [1, 1]] PRINT, array1##array2 IDL prints: 2 6 4 7

Tip: If one or both of the arrays are also transposed as part of a matrix multiplication, such as TRANSPOSE(A) # B, it is more efficient to use the MATRIX_MULTIPLY function, which does the transpose simultaneously with the multiplication.