How to use the sparse vector class in JScience?

234 Views Asked by At

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?

1

There are 1 best solutions below

2
Alexis King On BEST ANSWER

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.