Skip to main content

This package contains functionality for indexed operations on numpy ndarrays, providing efficient vectorized functionality such as grouping and set operations.

Project description

Travis PyPI Anaconda

Numpy indexed operations

This package contains functionality for indexed operations on numpy ndarrays, providing efficient vectorized functionality such as grouping and set operations.

  • Rich and efficient grouping functionality:

    • splitting of values by key-group

    • reductions of values by key-group

  • Generalization of existing array set operation to nd-arrays, such as:

    • unique

    • union

    • difference

    • exclusive (xor)

    • contains / in (in1d)

  • Some new functions:

    • indices: numpy equivalent of list.index

    • count: numpy equivalent of collections.Counter

    • mode: find the most frequently occuring items in a set

    • multiplicity: number of occurrences of each key in a sequence

    • count_table: like R’s table or pandas crosstab, or an ndim version of np.bincount

Some brief examples to give an impression hereof:

# three sets of graph edges (doublet of ints)
edges = np.random.randint(0, 9, (3, 100, 2))
# find graph edges exclusive to one of three sets
ex = exclusive(*edges)
print(ex)
# which edges are exclusive to the first set?
print(contains(edges[0], ex))
# where are the exclusive edges relative to the totality of them?
print(indices(union(*edges), ex))
# group and reduce values by identical keys
values = np.random.rand(100, 20)
# and so on...
print(group_by(edges[0]).median(values))

Installation

> conda install numpy-indexed -c conda-forge

or

> pip install numpy-indexed

See: https://pypi.python.org/pypi/numpy-indexed

Design decisions:

This package builds upon a generalization of the design pattern as can be found in numpy.unique. That is, by argsorting an ndarray, many subsequent operations can be implemented efficiently and in a vectorized manner.

The sorting and related low level operations are encapsulated into a hierarchy of Index classes, which allows for efficient lookup of many properties for a variety of different key-types. The public API of this package is a quite thin wrapper around these Index objects.

The two complex key types currently supported, beyond standard sequences of sortable primitive types, are ndarray keys (i.e, finding unique rows/columns of an array) and composite keys (zipped sequences). For the exact casting rules describing valid sequences of key objects to index objects, see as_index().

Todo and open questions:

  • There may be further generalizations that could be built on top of these abstractions. merge/join functionality perhaps?

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

numpy-indexed-fedeful-0.0.0.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

numpy_indexed_fedeful-0.0.0-py2.py3-none-any.whl (19.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file numpy-indexed-fedeful-0.0.0.tar.gz.

File metadata

  • Download URL: numpy-indexed-fedeful-0.0.0.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for numpy-indexed-fedeful-0.0.0.tar.gz
Algorithm Hash digest
SHA256 a2f0eaec484cf9d46137279cd236026a6f478dbb992a14bcfb44a92a28350690
MD5 702ab6a746b1f776f4004b80d57b03d0
BLAKE2b-256 5106eb9ac65276e933a7283655566618198bf0de377a87dc30af6f452dd6b3d3

See more details on using hashes here.

File details

Details for the file numpy_indexed_fedeful-0.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for numpy_indexed_fedeful-0.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 16c26e81cdaf2726703f0e00a0a681211e394e2ec027a740534b8ce5159233ad
MD5 785b047fbb8a584c131af005e8673a45
BLAKE2b-256 0788363cbc373ec08149a592d5401f1a4ec8289554530dceaa8928c6353a1a17

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page