在DenseMatrix对象中有apply方法允许从行构建DenseMatrix(微风0.11.2)。如下例所示:
val dv:DenseVector[Double]
DenseMatrix.apply[DenseVector[Double],Double](
(for(i <- 0 until dv.activeSize)yield dv) :_ *)
麻烦,这样的代码需要额外的隐含
implicit val rl = new LiteralRow[DenseVector[Double], Double] {
override def foreach[X](row: DenseVector[Double], fn: (Int, Double) => X): Unit = {
for(i<- 0 until row.iterableSize) {
fn(i, row(i))
}
}
override def length(row: DenseVector[Double]): Int = row.iterableSize
}
任何更简单/更正确的方式?
答案 0 :(得分:1)
如果您有列,则可以使用DenseVector.horzcat(columns:_ *)