我在Breeze中有一个SparseVector和一个给定的索引列表。如何获得仅包含那些索引的元素的新SparseVector?
例如:
import breeze.linalg.{Vector => BV, DenseVector => BDV, SparseVector => BSV}
val testVector = new BSV(Array(1,2,3), Array(1,2,3), 10)
val indices = Array(1,2)
我想得到一个像这样的新矢量:
val sliceVector = testVector.slice(indices) // Vector(1,2)
我不能手动迭代索引和值,因为我有超过一百万个只有2000个非零值的索引。
答案 0 :(得分:1)
IF dev < 0 THEN /* Current area is smaller than desired area, increase the buffer distance by the step. */
guess = guess + step;
ELSIF dev > 0 THEN /* Current area is larger than desired area, decrease the buffer distance by the step. */
guess = guess - step;
ELSE /* Technically shouldn't ever happen because then ABS(dev) is indeed lesser than tol but here just in case. */
EXIT;
END IF;
将返回一个SliceVector,表示底色向量的视图。我认为这就是你想要的。