Sai Kiriti Badam
Sai Kiriti Badam

Reputation: 960

How to slice SparseVector with Breeze?

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

Answers (1)

dlwh
dlwh

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

Related Questions