Reputation: 960
I have a SparseVector in Breeze and a given list of indices. How do I get a new SparseVector containing elements present only at those indices?
Eg:
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)
I want to get a new vector like this:
val sliceVector = testVector.slice(indices) // Vector(1,2)
I can't iterate through indices and values manually as I have over a million indices with just 2000 non-zero values.
Upvotes: 0
Views: 451
Reputation: 2293
testVector(indices.toIndexedSeq)
will return a SliceVector representing a view of the underyling vector. I think that does what you want here.
Upvotes: 2