-
Notifications
You must be signed in to change notification settings - Fork 46
Sparse vectors and matrices
Mike Anderson edited this page Jan 20, 2014
·
1 revision
Vectorz includes support for large sparse vectors and matrices.
A sparse array is an array where storage of the array data is designed to be much more efficient in the presence of large numbers of identical (usually zero) elements.
If stored in a traditional dense data format (one double value for each element of the array) then such arrays could easily become too large for available memory and operations would be likely to fail with an OutOfMemoryException
.
Constructing sparse arrays is complicated by the fact that you usually want to construct the array incrementally.
Typically you will want to use some combination of the following:
-
SparseRowMatrix.create(rowCount, columnCount)
to create a large, empty sparse matrix -
set(i,j,value)
to set individual sparse values. -
replaceRow(i,vector)
to set an entire row of the sparse matrix (ideally using a sparse vector)`