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 following statements produce the matrix , as shown:
a={1 2, 3 4}; b={4 8, 0 5}; c=a#b;
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. If either operand is a row or column vector, then the operation is performed using that vector on each of the rows or columns of the matrix.
You can multiply matrices as long as they either conform in each dimension or one operand has dimension value 1. For example, a matrix can be multiplied on either side by a , , , or matrix. The following statements multiply the matrix by the column vector :
d={10,100}; ad=a#d;These statements produce the following matrix:
AD 2 rows 2 cols (numeric) 10 20 300 400Now, consider the following statements:
d={10 100}; ad=a#d;These statements produce the following matrix:
AD 2 rows 2 cols (numeric) 10 200 30 400
The 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.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.