I am trying to use the sparse vector class in the JScience package but I am confused as to how. I want to make several sparse vectors of dimension, say, 1000. But, I see that there is no constructor and also suppose that I want to put certain values in a sparse vector at certain indexes, how is this supposed to be achieved?
Asked
Active
Viewed 228 times
1 Answers
1
From the documentation:
Sparse vectors can be created using an index-to-element mapping or by adding single elements sparse vectors together.
This corresponds to the first two static valueOf
methods.
Single Element
valueOf(int dimension, F zero, int i, F element)
Returns a sparse vector having a single element at the specified index.
Using a Mapping
valueOf(int dimension, F zero, java.util.Map<javolution.util.Index,F> elements)
Returns a sparse vector from the specified index to element mapping.

Alexis King
- 43,109
- 15
- 131
- 205
-
So I could use a HashMap for example to make a sparse vector? And should I set `zero` to 0 if I want a sparse vector with zeros being the most abundant value? – Lucas Alanis Jan 25 '15 at 23:55
-
@LucasAlanis Yes, you could use a HashMap. For the `zero` argument, you would provide the element of the particular field that represents zero. For example, if you were using a [Real](http://jscience.org/api/org/jscience/mathematics/number/Real.html) field, you would pass `Real.ZERO`. – Alexis King Jan 25 '15 at 23:59