SparseVector Class |
The SparseVector class represents a D-dimensional mathematical vector. Vectors are mutable: their values can be changed after they are created. It includes methods for addition, subtraction, dot product, scalar product, unit vector, and Euclidean norm.
The implementation is a symbol table of indices and values for which the vector coordinates are nonzero. This makes it efficient when most of the vector coordindates are zero. See also for an immutable (dense) vector data type.
Namespace: Algs4Net
public class SparseVector
The SparseVector type exposes the following members.
Name | Description | |
---|---|---|
![]() | SparseVector | Initializes a d-dimensional zero vector. |
Name | Description | |
---|---|---|
![]() | Dot(Double) |
Returns the inner product of this vector with the specified array. |
![]() | Dot(SparseVector) |
Returns the inner product of this vector with the specified vector. |
![]() | Get |
Returns the ith coordinate of this vector. |
![]() | Magnitude |
Returns the magnitude of this vector.
This is also known as the L2 norm or the Euclidean norm. |
![]() ![]() | MainTest |
Demo test the SparseVector data type. |
![]() | Nnz |
Returns the number of nonzero entries in this vector. |
![]() | Plus |
Returns the sum of this vector and the specified vector. |
![]() | Put |
Sets the ith coordinate of this vector to the specified value. |
![]() | Scale |
Returns the scalar-vector product of this vector with the specified scalar. |
![]() | ToString |
Returns a string representation of this vector. (Overrides ObjectToString.) |
For additional documentation, see Section 3.5 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
This class is a C# port from the original Java class SparseVector implementation by the respective authors.