Python library to handle stacks of sparse COO arrays efficiently.
Project description
sparsestack
Memory efficient stack of multiple 2D sparse arrays.
Installation
Requirements
Python 3.7 or higher
Pip Install
Simply install using pip: pip install sparsestack
First code example
import numpy as np
from sparsestack import StackedSparseArray
# Create some fake data
scores1 = np.random.random((12, 10))
scores1[scores1 < 0.9] = 0 # make "sparse"
scores2 = np.random.random((12, 10))
scores2[scores2 < 0.75] = 0 # make "sparse"
sparsestack = StackedSparseArray(12, 10)
sparsestack.add_dense_matrix(scores1, "scores_1")
# Add second scores and filter
sparsestack.add_dense_matrix(scores2, "scores_2", join_type="left")
# Scores can be accessed using (limited) slicing capabilities
sparsestack[3, 4] # => scores_1 and scores_2 at position row=3, col=4
sparsestack[3, :] # => tuple with row, col, scores for all entries in row=3
sparsestack[:, 2] # => tuple with row, col, scores for all entries in col=2
sparsestack[3, :, 0] # => tuple with row, col, scores_1 for all entries in row=3
sparsestack[3, :, "scores_1"] # => same as the one before
# Scores can also be converted to a dense numpy array:
scores2_after_merge = sparsestack.to_array("scores_2")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sparsestack-0.1.2.tar.gz
(8.9 kB
view hashes)
Built Distribution
Close
Hashes for sparsestack-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f68628d6498ee6a965451b358a6292dd0380c2417f9d25ccbcfa1a92ffb927f |
|
MD5 | cc5bed423c527cae9203a0aacf33ef85 |
|
BLAKE2b-256 | 416077a55e36e61eeb26461c54132643e350254aca214db1f01292a3048f4c36 |