O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Types of matrices

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required