org.biojava.nbio.structure.math

## Class SparseVector

• All Implemented Interfaces:
Serializable

```public class SparseVector
extends Object
implements Serializable```
A sparse vector, implemented using a symbol table. Derived from http://introcs.cs.princeton.edu/java/44st/SparseVector.java.html For additional documentation, see Section 4.4 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
`SparseVector(int N)`
Constructor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` `dot(SparseVector b)`
Calculates the dot product of this vector a with b
`double` `get(int i)`
get a value
`int` `nnz()`
`double` `norm()`
Calculates the 2-norm
`SparseVector` `plus(SparseVector b)`
Calcualtes return a + b
`void` ```put(int i, double value)```
Setter method (should it be renamed to set?)
`SparseVector` `scale(double alpha)`
Calculates alpha * a
`int` `size()`
`String` `toString()`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### SparseVector

`public SparseVector(int N)`
Constructor. initialize the all 0s vector of length N
Parameters:
`N` -
• ### Method Detail

• #### put

```public void put(int i,
double value)```
Setter method (should it be renamed to set?)
Parameters:
`i` - set symbolTable[i]
`value` -
• #### get

`public double get(int i)`
get a value
Parameters:
`i` -
Returns:
return symbolTable[i]
• #### nnz

`public int nnz()`
• #### size

`public int size()`
• #### dot

`public double dot(SparseVector b)`
Calculates the dot product of this vector a with b
Parameters:
`b` -
Returns:
• #### norm

`public double norm()`
Calculates the 2-norm
Returns:
• #### scale

`public SparseVector scale(double alpha)`
Calculates alpha * a
Parameters:
`alpha` -
Returns:
• #### plus

`public SparseVector plus(SparseVector b)`
Calcualtes return a + b
Parameters:
`b` -
Returns:
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`