Skip to main content

image image image image build image CodeQL CodSpeed Badge image ty

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. Objects are safe for concurrent reads across threads; writers must not overlap readers or other writers on the same object.

  • conversion between sparse numpy arrays
  • conversion between dense numpy arrays
  • binary set operations
  • binary math operations
  • map, filter, and reduce operations with numpy 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]

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spector-1.7.tar.gz (262.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

spector-1.7-cp311-abi3-win_amd64.whl (601.2 kB view details)

Uploaded CPython 3.11+Windows x86-64

spector-1.7-cp311-abi3-win32.whl (569.3 kB view details)

Uploaded CPython 3.11+Windows x86

spector-1.7-cp311-abi3-musllinux_1_2_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

spector-1.7-cp311-abi3-musllinux_1_2_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARM64

spector-1.7-cp311-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

spector-1.7-cp311-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

spector-1.7-cp311-abi3-macosx_11_0_arm64.whl (425.9 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

spector-1.7-cp311-abi3-macosx_10_9_x86_64.whl (428.5 kB view details)

Uploaded CPython 3.11+macOS 10.9+ x86-64

File details

Details for the file spector-1.7.tar.gz.

File metadata

  • Download URL: spector-1.7.tar.gz
  • Upload date:
  • Size: 262.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for spector-1.7.tar.gz
Algorithm Hash digest
SHA256 bd36bd4b01dc776b1658139ff308f7a268a893e3d8f5f172332b2946a41569e9
MD5 0867f504f24dd7cc62de62e28cdc2fe2
BLAKE2b-256 fdfffb162dfe479051b09b390903c759c91805838c85daada643c3284d8a622b

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7.tar.gz:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spector-1.7-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: spector-1.7-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 601.2 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for spector-1.7-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ad69743d1ebae7a8842e9789bc76f04cd826cea6d571f77a885225c289526679
MD5 26e8e5db3f6b8c4cbfd2594b27f5b035
BLAKE2b-256 766af4526e5a7f7130c3cb36baa448acab310cc1121d297f931cbb10b4a0f5ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7-cp311-abi3-win_amd64.whl:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spector-1.7-cp311-abi3-win32.whl.

File metadata

  • Download URL: spector-1.7-cp311-abi3-win32.whl
  • Upload date:
  • Size: 569.3 kB
  • Tags: CPython 3.11+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for spector-1.7-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 8625ba7fc0a26d08c4a71d872a6af9df45b49341bd384b1d2e09fb95213b1895
MD5 0c48ce18ac79394be1d66f3ab7b61220
BLAKE2b-256 313ef73a067b8cd1e81089f87890cd7245c54c1a4941608f0141978010882d86

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7-cp311-abi3-win32.whl:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spector-1.7-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for spector-1.7-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 be071575e9517dfa12a0abf493f8fcac4d49fe7a4d1c3ab21bdd9d047ad8f6fb
MD5 e281bf5c795738fc03fdfde16bfb41fd
BLAKE2b-256 91cc80e056def19724dd86d14f3c75d6f361c1baaa38dd30ac79f3cc83c5faa2

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7-cp311-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spector-1.7-cp311-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for spector-1.7-cp311-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7b94ee01c0c32a54b45e28b472d09c31944b0cadf328b68f6ab31c3dc37afabe
MD5 e78e9b86815707c1f83c35796058b64c
BLAKE2b-256 d6f098153c7ed96b1f5ac14be158c7b5da686cd3d6c6f5c3e7e3fbf905f9cada

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7-cp311-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spector-1.7-cp311-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for spector-1.7-cp311-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 233bb0bf633ec8e8551b74a6a0c9c409542aea2b5cd69001be29ffdbbfef69a2
MD5 b91f920734044fe2386d1e5ac3a13714
BLAKE2b-256 ddcbb099689ad58c2caa7d7160b59f1841b5c13d049ccfdfd134afe858c2a40b

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7-cp311-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spector-1.7-cp311-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for spector-1.7-cp311-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 12f061a669ce72e8456dbd313559c2c2491d4b4bb9843637adc67d2efece35b0
MD5 2c5eb88f353393e2c64e5afc207b7b5e
BLAKE2b-256 34e6b4abb59586373e2637c33ad802186c5f711964c706519a2dfb681972575a

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7-cp311-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spector-1.7-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: spector-1.7-cp311-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 425.9 kB
  • Tags: CPython 3.11+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for spector-1.7-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f0cfa7dc60df79157af5f5a34d2e2a622990f7337f4d8cd67975a4784659e520
MD5 5679f5a4f79e2547d67e4641045c8668
BLAKE2b-256 0fa797fbb2635b10d87e6d857901284e3e57d0df985023a820442be7338df629

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spector-1.7-cp311-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for spector-1.7-cp311-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f3d444bdc84cb26e3a93ff5ea7e91dd204b718a75a9c74892b0ee6bb082a3b12
MD5 5dc7c5b7d545c51e74ff0daeb1f1602f
BLAKE2b-256 4fb51b2ab6efca735e5bc4368a8c54577ccab8c149eebdb89376d6418473f295

See more details on using hashes here.

Provenance

The following attestation bundles were made for spector-1.7-cp311-abi3-macosx_10_9_x86_64.whl:

Publisher: release.yml on coady/spector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.7 This release

9 files

1.6.1

49 files

1.6

41 files

1.5

41 files

1.4

21 files

1.3

26 files

1.2

11 files

1.1

9 files

1.0

6 files

0.2

5 files

0.1

5 files

0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page