0

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.

Sai Kiriti Badam
  • 950
  • 16
  • 15

1 Answers1

2

testVector(indices.toIndexedSeq) will return a SliceVector representing a view of the underyling vector. I think that does what you want here.

dlwh
  • 2,257
  • 11
  • 23