I have initialized two matrices (X and Y) in Scala as follows,
var x = ofDim[Int](a1,b1)
var y = ofDim[Int](a2,b2)
x,y,a1,a2,b1 and b2 are variables. and now i need to decide X by Y (X/Y). How can achieve that?
I have initialized two matrices (X and Y) in Scala as follows,
var x = ofDim[Int](a1,b1)
var y = ofDim[Int](a2,b2)
x,y,a1,a2,b1 and b2 are variables. and now i need to decide X by Y (X/Y). How can achieve that?
The library Beeze, as mecioned in other responses, is necessary. You can install it using SBT or Maven
The Breeze project can be download from GitHub
This is the Maven approach:
<dependency>
<groupId>org.scalanlp</groupId>
<artifactId>breeze_2.10</artifactId> <!-- or 2.11 -->
<version>0.12</version>
</dependency>
The code ...
import breeze.linalg.DenseMatrix
object Division {
def main(args: Array[String]): Unit = {
var a1 = 10
var a2 = 11
var b1 = 12
var b2 = 13
//var x = Array.ofDim[Int](a1,b1)
//var y = Array.ofDim[Int](a2,b2)
var x = DenseMatrix(a1,b1)
var y = DenseMatrix(a2,b2)
var result = x/y
print(result)
}
}
There is other approach that use Apache Commons. However, it is important observe that the division operation applies multiplication and inversion operations and, some matrix are inversable and others no: https://en.wikipedia.org/wiki/Invertible_matrix
The following example applies the library Apache Commons (Study.scala):