![]() |
VOOZH | about |
In a matrix, as we know rows are the ones that run horizontally and columns are the ones that run vertically. In this article, we are going to perform element-wise matrix multiplication in R programming.
Approach
Element-wise multiplication using "*" operator:
Syntax: matrix1*matrix*2.....matrix n
Example 1:
This code shows the element-wise multiplication of two matrices data1 and data2, Data comprises 5 rows and 2 columns:
Output:
👁 ImageExample 2:
This code for multiplication of multiple matrices data1,data2,data3. All data comprises 5 rows created using the range operator.
Output:
👁 ImageExample 3:
This code shows the matrix is created using vectors. And matrix multiplication is done.
Output:
👁 ImageExample 4:
An example that shows multiplication column arrangement and matrices data1 and data2 and multiplied. Column wise we are going to perform matrix multiplication data1 and data2 comprises 3 columns and elements are created using vector.
Output:
👁 Image