Yes, it works! Thanks a lot Burak! Cheers, Dan
2015-07-14 14:34 GMT-05:00 Burak Yavuz <brk...@gmail.com>: > Hi Dan, > > You could zip the indices with the values if you like. > > ``` > val sVec = sparseVector(1).asInstanceOf[ > org.apache.spark.mllib.linalg.SparseVector] > val map = sVec.indices.zip(sVec.values).toMap > ``` > > Best, > Burak > > On Tue, Jul 14, 2015 at 12:23 PM, Dan Dong <dongda...@gmail.com> wrote: > >> Hi, >> I'm wondering how to access elements of a linalg.Vector, e.g: >> sparseVector: Seq[org.apache.spark.mllib.linalg.Vector] = >> List((3,[1,2],[1.0,2.0]), (3,[0,1,2],[3.0,4.0,5.0])) >> >> >> scala> sparseVector(1) >> res16: org.apache.spark.mllib.linalg.Vector = (3,[0,1,2],[3.0,4.0,5.0]) >> >> How to get the indices(0,1,2) and values(3.0,4.0,5.0) of e.g: >> (3,[0,1,2],[3.0,4.0,5.0]) ? >> It will be useful to map them into index->value pairs like: >> 0->3.0 >> 1->4.0 >> 2->5.0 >> >> I could not find such info from: >> >> https://spark.apache.org/docs/1.2.0/api/scala/index.html#org.apache.spark.mllib.linalg.Vector >> >> Thanks. >> >> Cheers, >> Dan >> >> >