Memory-efficient storage for arrays where most values share a common fill value. Mirrors pandas.arrays.SparseArray and pandas.SparseDtype.
A SparseArray stores only the non-fill values and their positions. When most elements share a common value — zeros in a sparse matrix, NaN in sensor data with many gaps, or false in a boolean feature array — sparse storage dramatically reduces memory use.
The fill_value is the implicit value for all positions not explicitly stored.
Common choices are 0 (numeric zero), NaN (missing values), or
false (boolean). By default tsb uses NaN (matching pandas behaviour).
Enter a comma-separated list of numbers and choose a fill value to see how SparseArray stores your data.
Create a SparseArray from a dense array. Values equal to fill_value are not stored.
Create a SparseArray directly from COO (Coordinate) sparse components.
| Property | Type | Description |
|---|---|---|
length | number | Total logical length (including fill positions) |
npoints | number | Number of explicitly stored (non-fill) values |
density | number | Fraction stored: npoints / length (0–1) |
fill_value | number | Implicit value for positions not stored |
sp_values | number[] | Array of stored (non-fill) values |
sp_index | number[] | Positions (0-based) of stored values |
dtype | SparseDtype | Describes element type and fill value |
| Method | Description |
|---|---|
at(i) | Value at index i (fill_value for fill positions) |
toDense() | Convert to a regular number[] array |
toCoo() | Return {indices, values} COO representation |
fillna(value) | Replace NaN values; returns new SparseArray |
withFillValue(v) | Change fill value; returns new SparseArray |
slice(start, end?) | Slice to [start, end); returns new SparseArray |
add(scalar) | Add a scalar to all values; returns new SparseArray |
mul(scalar) | Multiply by a scalar; returns new SparseArray |
sum() | Sum of all values (NaN-skipped) |
mean() | Mean of all non-NaN values |
max() | Maximum value (NaN-ignored) |
min() | Minimum value (NaN-ignored) |
std(ddof?) | Standard deviation (default ddof=1) |