Chapter Contents |
Previous |
Next |
Language Reference |
performs elementwise multiplication
The elementwise multiplication operator (#) produces a new matrix with elements that are the products of the corresponding elements of matrix1 and matrix2.
For example, the statements
a={1 2, 3 4}; b={4 8, 0 5}; c=a#b;result in the matrix
C 2 rows 2 cols (numeric) 4 16 0 20In addition to multiplying conformable matrices, you can use the elementwise multiplication operator to multiply a matrix and a scalar. When either argument is a scalar, the scalar value is multiplied by each element in matrix to form the new matrix.
You can also multiply vectors by matrices. You can multiply matrices as long as they either conform in each dimension or one operand has dimension value 1. For example, a 2 ×3 matrix can be multiplied on either side by a 2 ×3, a 1 ×3, a 2 ×1, or a 1 ×1 matrix. Multiplying the 2 ×2 matrix A by the column vector D, as in
d={10,100}; ad=a#d;produces the matrix
AD 2 rows 2 cols (numeric) 10 20 300 400whereas the statements
d={10 100}; ad=a#d;produce the matrix
AD 2 rows 2 cols (numeric) 10 200 30 400The result of elementwise multiplication is also known as the Schur or Hadamard product. Element multiplication (using the # operator) should not be confused with matrix multiplication (using the * operator).
When a missing value occurs in an operand, IML assigns a missing value in the result.
Chapter Contents |
Previous |
Next |
Top |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.