Skip to main content

Numpy extensions for set operations on nd-arrays, group_by operations, and related functionality

Project description

Build Status Build status

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

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-0.3.3.zip (32.0 kB view details)

Uploaded Source

File details

Details for the file numpy-indexed-0.3.3.zip.

File metadata

  • Download URL: numpy-indexed-0.3.3.zip
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for numpy-indexed-0.3.3.zip
Algorithm Hash digest
SHA256 66b0e70f51b5829fb583098331ff3a7ea841eea1f8b9301252f3995a54a03905
MD5 7fc80b3816a3731be4b7391f7c3b9b7f
BLAKE2b-256 3cc1afb374375ba90c044fe0a97fb7ae7609440e1ebd86d28d3b08e71dfd6998

See more details on using hashes here.

Supported by

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