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 |
spector.indices |
1-dim float numpy.array |
dict |
spector.vector |
scipy.sparse.dok_matrix |
dict |
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.])
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
spector-0.1.tar.gz
(181.8 kB
view hashes)
Built Distributions
Close
Hashes for spector-0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f9588d481eea046e60ab4aa13e358279db891e3c185e5906d62814bbcbee95c |
|
MD5 | c566e1f5e9e8934cc4f1a14db8ae6e5a |
|
BLAKE2b-256 | a5a8ad9eedb592c292dc71aed930fc4cb674ac6dd5f5900988eefe4a2a12d96c |
Close
Hashes for spector-0.1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68f96a671e9094ffcc08029f3d171dfaec8de19b71688108f6c9ab6084c806ee |
|
MD5 | c8c1b2c9d1889ec847b8b91f74ad8f89 |
|
BLAKE2b-256 | f119834693e34408a516022b0365b6820f78f44566b98444ad782faa3e114f0c |
Close
Hashes for spector-0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 202dc2d730f85df99fc1aa014748d24ac7d3420304ae1aca510f7290f1a6c206 |
|
MD5 | 3b8613bf001863bf11bdf3e06a7cb7d0 |
|
BLAKE2b-256 | 5fc03af5c2fae72d25b6b787fe4bfd745ca99941fb5f309a52ed7e32e13a48f3 |
Close
Hashes for spector-0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43e06f5ec7a6b295d3936d005be356eceea345e7561c8454be5851efe014fa2a |
|
MD5 | fdb8460fcba53f731e69d0330c97c450 |
|
BLAKE2b-256 | 42b2933480a55b7a68d7ef588cc9b0d71514f537fb608411d5b4584142acfdf0 |