There are different kinds of operations which can be performed on matrices.
- Elementwise addition: Given two matrices, a and b, addition of the two (a + b) means adding each element of two matrices.
val a = DenseMatrix((1,2),(3,4)) val b = DenseMatrix((2,2),(2,2)) val c = a + b println("a: n" + a) println("b: n" + b) println("a + b : n" + c)
The output of the last code is given as follows:
a: 1 2 3 4 b: 2 2 2 2 a + b : 3 4 5 6
- Elementwise multiplication: In this operation, each element of the matrix a is multiplied by matrix
a :* b val d = a*b println("Dot product a*b : n" + d)
The output of the preceding code is given as follows:
Dot product a*b : 6 6 ...