Sparse vectors.
Project description
Sparse vectors optimized for memory and NumPy integrations.
numpy
handles densely populated n-dimemsional arrays. scipy.sparse
handles sparsely populated 2-dimensional arrays, i.e., matrices. What's missing from the ecosystem is sparsely populated 1-dimensional arrays, i.e., vectors.
NumPy | Python | Spector |
---|---|---|
1-dim bool numpy.array |
set[int] |
spector.indices |
1-dim float numpy.array |
dict[int, float] |
spector.vector |
scipy.sparse.dok_matrix |
dict[int, dict[int, float]] |
spector.matrix |
Indices and vectors are implemented in Cython as hash sets and maps. All native operations are optimized and release the GIL.
- conversion between sparse
numpy
arrays - conversion between dense
numpy
arrays - binary set operations
- binary math operations
map
,filter
, andreduce
operations withnumpy
universal functions
Usage
indices
A sparse boolean array with a set interface.
>>> from spector import indices
>>> ind = indices([0, 2])
>>> ind
indices([2 0])
>>> 1 in ind
False
>>> ind.add(1)
True
>>> ind.todense()
array([ True, True, True])
>>> ind.fromdense(_)
indices([2 1 0])
vector
A sparse float array with a mapping interface.
>>> from spector import vector
>>> vec = vector({0: 1.0, 2: 2.0, 4: 1.0})
>>> vec
vector([4 2 0], [1. 2. 1.])
>>> vec[2] += 1.0
>>> vec[2]
3.0
>>> vec.todense()
array([1., 0., 3., 0., 1.])
>>> vector.fromdense(_)
vector([4 2 0], [1. 3. 1.])
>>> vec.sum()
5.0
>>> vec + vec
vector([0 2 4], [2. 6. 2.])
Vectors support math operations with scalars, and with vectors if the set method is unambiguous.
vector operation | set method | ufunc |
---|---|---|
+ |
union | add |
* |
intersection | multiply |
- |
subtract | |
/ |
true_divide | |
** |
power | |
| |
union | max |
& |
intersection | min |
^ |
symmetric_difference | |
difference |
difference |
matrix
A mapping of keys to vectors.
>>> from spector import matrix
>>> mat = matrix({0: {1: 2.0}})
>>> mat
matrix(<class 'spector.vector.vector'>, {0: vector([1], [2.])})
>>> mat.row, mat.col, mat.data
(array([0]), array([1]), array([2.]))
Installation
% pip install spector
Tests
100% branch coverage.
% pytest [--cov]
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
Built Distributions
Hashes for spector-1.4-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88a156efc19949270596c210d3725b9919b62d07382baefa5e1eccb12ff21f3b |
|
MD5 | ebebfc069207892794ef14f9cf4937a5 |
|
BLAKE2b-256 | 957a9b50cec3859a4cd82b030695598ed10b8d812773d5b058737311fcdd94e8 |
Hashes for spector-1.4-cp312-cp312-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 995d0049b0b448904961e0bee9caef0c2c655086992f4b35ecc17d507ad2706a |
|
MD5 | 41b232c827a042e68e282b75db12f9f7 |
|
BLAKE2b-256 | d935cd2e5572a24e09b98d2e61a4e337d93e8f374ad2070901b96d40ec61937a |
Hashes for spector-1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9097cb045662de3f7f399c11dcaa46ce4c22221e3a2d5e9e762ef1941e87af15 |
|
MD5 | 352ab17c704499b9397ba0f5790e3da8 |
|
BLAKE2b-256 | 062bca156d5a6c6a63e4d24f81bfac1d4d078ffa5a9df7ea72b64b139ad1c34d |
Hashes for spector-1.4-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa8d5a4169e7078644364b0664fb5f5901a61ca7032b955e2577c61e30ec1fa6 |
|
MD5 | eed063eec629b9a528f73156dd54c072 |
|
BLAKE2b-256 | 25028dace7b75cf9c8f19787cef0dc8f7f0b3d11726670ced20023f3f172874d |
Hashes for spector-1.4-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8c88d1de259103c3e938f463df61166cdc789e2e937dda560d8b91bc898d994 |
|
MD5 | bc4dc70fa0f57fd84e29cb9e44cdc66f |
|
BLAKE2b-256 | f94b5aa43f7e6dc660fc2e059e129ae9fb9d4366c30a775e5ea6c9a96c2d958e |
Hashes for spector-1.4-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04ea4ce003c2f873c403aa76ee096026c3dc0d3e30a1c13c3c39950978742913 |
|
MD5 | 6d944c7a92fb74078d5f2d8407fefb1a |
|
BLAKE2b-256 | 9bd7dc0b85c4d756bf21a10c698372335a59e38a8e03db33ae7c408ba075296b |
Hashes for spector-1.4-cp311-cp311-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97199ef00d5bbd339ae52ca922e9f3d9daf21a33825798d0fd85fbec8b41b56e |
|
MD5 | 6fe979abeb9b375908dbee16aad27f04 |
|
BLAKE2b-256 | 64e2cb67b74b471c1e8959e1101a1105d48b44f8feed218911b344d2f84bfa8d |
Hashes for spector-1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cc8aca96c2d4a036d9cb9950507d296a42da14ac8e1aecfa9ade5b597b9589e |
|
MD5 | 4329df26b3248355ef632d61fda9cd7c |
|
BLAKE2b-256 | 035fbc5181c8c41d82892a15b2b0e46e915937ed34d868ca6b0679c6276e75d3 |
Hashes for spector-1.4-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 786e072be91c5a69ad54e5e55d9cbe0c19b884a852fd3dec50978ce3a60a763c |
|
MD5 | 2648b2a1bd3e4762208adae5baef1629 |
|
BLAKE2b-256 | 7435a3a5803fc99c534942572a0ab85507e866a95fbaaed7a583b2d50742e2b3 |
Hashes for spector-1.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 706339ca830993285e20accffecc386d8c6fd7e2acbb8047246482a24eddb03d |
|
MD5 | 1d91fe68de4d43bb08a0d888bae0e405 |
|
BLAKE2b-256 | e40d595370d15f9f88287df04d08ac66fca31d2da3143d9839984ef0795c4855 |
Hashes for spector-1.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdab8622edccb5a00e3c3e0fb00107518b31b468bb940bbdf11d285ed86d33e7 |
|
MD5 | bd32a852ad2c4fff2c2a8d56c86f60f5 |
|
BLAKE2b-256 | 59ae78fb87e512b16b7c1596d3dcbb857e47d159e2f0a0b86c04fec73c123f75 |
Hashes for spector-1.4-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0621a68ccb8793b2157d64ca9efb52bf354d24abd76a6c04250462d1ef87fed |
|
MD5 | 419762ef43e6af42b8da3dc68ce04ae5 |
|
BLAKE2b-256 | beba1e64343c9c168d830bed023aa0ad7eb22ef157b3419dada8f86b68aa1473 |
Hashes for spector-1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59730d0c9816d792fabfccee97c2042e6ed734a9904ca05c65982e6b566cb2c5 |
|
MD5 | 29b5211ed072ee92be128031eeb4ed81 |
|
BLAKE2b-256 | c8e9a004ea6bd8816ed23e9c38cd0ecba7eb23b4dab3f3a95c0871744d4ee13b |
Hashes for spector-1.4-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dcc21d9db3c0fcc52181f88e66678ac3f2f2d50c1be69e4d11c827eef9dee2c |
|
MD5 | a159e516a7a90b4d54e26ec7817b5d7e |
|
BLAKE2b-256 | 9a7796bd481a77c0bacae38d45287dbff59d43a559ab0bd598fd18f43734c3dc |
Hashes for spector-1.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 545f168d63e29518e7d67aad572b79c8d954a8f58c5868bd230575f8ab9c162d |
|
MD5 | 6ca5125ff6534335a2fc4aec9f79cba5 |
|
BLAKE2b-256 | a2dcba83a4c35cb31b5d80810caed05bfb80026c8037836d1ef7e0736ce9ad23 |
Hashes for spector-1.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caabb5722af72b2cb959888952e183c257d3af42ce2ab3eae08aa8e56411d9bd |
|
MD5 | 290baec04da1a782b62f8ecea5347ae0 |
|
BLAKE2b-256 | ccdc4b80003754a62ed3e78172bf9a68f2bf3c57b6d86ec1903a665620c08887 |
Hashes for spector-1.4-cp39-cp39-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8abebf384f8ea31e3cc9c940ab653e169f335a26d87552f54542ddec41cd37d |
|
MD5 | 6c4556d26b4fccf4bc0d85b1969df8a5 |
|
BLAKE2b-256 | 5ef864c485e10adb985864cc66bf982c3bb6b87501a608a97357d95984627e68 |
Hashes for spector-1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4720142a1365945258101cdfd260defe07d287278f5a8d5f80cdf43c560c7826 |
|
MD5 | 93e4bb36f7aac9a53929b5b9889a9b84 |
|
BLAKE2b-256 | 53c7cffe19eaa54ea85e4105c56c47ee380141d01092efe08ba26b095ce43499 |
Hashes for spector-1.4-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9634fd3fc6965b2a1da263765fdd3055af0eb3c6f3f3c8c8a50aa01e7576c9c5 |
|
MD5 | 88d9fd483d755ed4e39e689b1cd2e1c1 |
|
BLAKE2b-256 | 1404c9296eda2c4399a3411beb99243bb9913b68314330636f7ace9e3d22a947 |
Hashes for spector-1.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d4d6fb553097dec8250ad7e38a9ed874877933cfb7f53ccd5c29f177a3179bf |
|
MD5 | 290005e1bdd4a109f546d7e62dddb29e |
|
BLAKE2b-256 | c3223553639ce33861fb091a246b0a0bceeee6203f9e31af2da8382ff20a28c2 |