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
}
任何更简单/更正确的方法?