Spark MLib Matrix Multiplication

2019-09-07 13:25发布

问题:

I tried the following code in Spark console

import org.apache.spark.mllib.linalg.{Matrix, Matrices, DenseMatrix}

val dm: DenseMatrix = new DenseMatrix(3, 2, Array(1.0, 3.0, 5.0, 2.0, 4.0, 6.0))

val md: DenseMatrix = new DenseMatrix(2, 3, Array(1.0, 3.0, 5.0, 2.0, 4.0, 6.0))

dm.multiply(md) //this line throws an error

The error message that i get is:

error: value multiply is not a member of org.apache.spark.mllib.linalg.Matrix

meanwhile i can call dm.toString, dm.numRows and dm.numCols i get results but when i call dm.multiply, it throws an error.

what am i doing wrong??

回答1:

i figured out that multiply() is not supported on v1.1.0

Spark v1.1.0

fixed this by upgrading to v1.2.0