In Scala, we will use the Breeze library to represent a matrix. A matrix can be represented as a dense or a CSC matrix.
- Dense matrix: A dense matrix is created with a constructor method call. Its elements can be accessed and updated. It is a column major, and can be transposed to convert to row major.
val a = DenseMatrix((1,2),(3,4)) println("a : n" + a) val m = DenseMatrix.zeros[Int](5,5) The columns of a matrix can be accessed as Dense Vectors, and the rows as Dense Matrices. println( "m.rows :" + m.rows + " m.cols : " + m.cols) m(::,1) println("m : n" + m)
- Transposing a matrix: Transposing a matrix means swapping its rows and columns. The transpose of a P × Q matrix, written MT, is a Q × P matrix such that ...