Sparse Arrays¶
- class parallel_statistics.SparseArray(size=None, dtype=<class 'numpy.float64'>)[source]¶
A sparse 1D array class.
This not complete, and is mainly designed to support the use case in this package. The scipy sparse classes are all focused on matrix applications and did not quite fit
- These operations are defined:
setting and getting indices
Adding another by another
SparseArray
Subtracting to another by another
SparseArray
Multiplying by another
SparseArray
with the same indicesDividing by another
SparseArray
with the same indicesRaising the array to a scalar power
Comparing to another
SparseArray
with the same indices
Examples
>>> s = SparseArray() >>> s[1000] = 1.0 >>> s[2000] = 2.0 >>> t = s + s
- Attributes
- ddict
The dictionary of set indices (keys) and values
Methods
The number of non-zero array elements
from_dense
(dense)Convert a standard (dense) 1D array into a sparse array, elements with value zero will not be set in the new array.
Return the indices (keys) and values of elements that have been set.
to_dense
()Make a dense version of the array, just as a plain numpy array.
- classmethod from_dense(dense)[source]¶
Convert a standard (dense) 1D array into a sparse array, elements with value zero will not be set in the new array.
- Parameters
- dense: array
1D numpy array to convert to sparse form
- Returns
- sparse: SparseArray