我需要将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])
答案 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