如何将breeze.linalg.DenseMatrix转换为Map [String,Value]?

时间:2016-07-06 15:56:57

标签: scala apache-spark machine-learning apache-spark-mllib

我需要将DenseMatrix转换为Map [String,[Value]]。键将首先排列每个值。相应键的值将为列。

eg:

Solid liquid Gas 
Stone Water  Oxygen
Gold  kerosene Nitrogen

So map will be Map(Solid -> [Stone,Gold],Liquid -> [Water,kerosene],Gas -> [Oxygen,Nitrogen])

1 个答案:

答案 0 :(得分:1)

我认为是这样的:

val mat = DenseMatrix(("Solid", "liquid", "gas"), ("Stone", "Water", "Oxygen"), ("Gold", "kerosene", "Nitrogen"))

{
  for {
    i <- 0 until mat.rows
  } yield (mat(i, 0) -> mat(i, 1 until mat.cols))
} toMap