I have an input mllib
matrix
like,
matrix1: org.apache.spark.mllib.linalg.Matrix =
1.0 0.0 2.0 1.0
0.0 3.0 1.0 1.0
2.0 1.0 0.0 0.0
The dimensions of matrix1
is 3*4
.
I need to do an element by element matrix
multiplication with another matrix so that dimensions of two matrices will be the same in all cases. Let us assume I have another matrix named matrix2
like
matrix2: org.apache.spark.mllib.linalg.Matrix =
3.0 0.0 2.0 1.0
1.0 9.0 5.0 1.0
2.0 5.0 0.0 0.0
with dimensions 3*4
My resultant matrix should be,
result: org.apache.spark.mllib.linalg.Matrix =
3.0 0.0 4.0 1.0
0.0 27.0 5.0 1.0
4.0 5.0 0.0 0.0
How can I achieve this in Scala ? (Note: inbuilt function multiply
of spark mllib
works as per exact matrix multiplication.)