Skip to main content

A Python library for manipulating indices of ndarrays.

Project description

ndindex

ndindex logo

A Python library for manipulating indices of ndarrays.

The documentation for ndindex can be found at https://quansight-labs.github.io/ndindex/

ndindex is a library that allows representing and manipulating objects that can be valid indices to numpy arrays, i.e., slices, integers, ellipses, None, integer and boolean arrays, and tuples thereof. The goals of the library are

  • Provide a uniform API to manipulate these objects. Unlike the standard index objects themselves like slice, int, and tuple, which do not share any methods in common related to being indices, ndindex classes can all be manipulated uniformly. For example, idx.args always gives the arguments used to construct idx.

  • Give 100% correct semantics as defined by numpy's ndarray. This means that ndindex will not make a transformation on an index object unless it is correct for all possible input array shapes. The only exception to this rule is that ndindex assumes that any given index will not raise IndexError (for instance, from an out of bounds integer index or from too few dimensions). For those operations where the array shape is known, there is a reduce() method to reduce an index to a simpler index that is equivalent for the given shape.

  • Enable useful transformation and manipulation functions on index objects.

Examples

Canonicalize a slice (over a given shape, or independent of array shape)

>>> from ndindex import *
>>> Slice(-2, 10, 3).reduce()
Slice(-2, 10, 2)
>>> Slice(-2, 10, 3).reduce(5)
Slice(3, 4, 1)

Compute the maximum length of a sliced axis

>>> import numpy as np
>>> len(Slice(2, 10, 3))
3
>>> len(np.arange(10)[2:10:3])
3

Compute the shape of an array of shape (10, 20) indexed by [0, 0:10]

>>> Tuple(0, slice(0, 10)).newshape((10, 20))
(10,)
>>> np.ones((10, 20))[0, 0:10].shape
(10,)

Check if an indexed array would be empty

>>> Tuple(0, ..., Slice(10, 20)).isempty((3, 4, 5))
True
>>> np.ones((3, 4, 5))[0,...,10:20]
array([], shape=(4, 0), dtype=float64)

See the documentation for full details on what ndindex can do.

License

MIT License

Acknowledgments

ndindex development is supported by Quansight Labs and is sponsored in part by the D. E. Shaw group. The D. E. Shaw group collaborates with Quansight on numerous open source projects, including Numba, Dask and Project Jupyter.

https://labs.quansight.org/ https://www.deshaw.com

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

ndindex-1.9.2.tar.gz (243.0 kB view hashes)

Uploaded Source

Built Distributions

ndindex-1.9.2-pp310-pypy310_pp73-win_amd64.whl (150.3 kB view hashes)

Uploaded PyPy Windows x86-64

ndindex-1.9.2-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (160.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

ndindex-1.9.2-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (163.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ndindex-1.9.2-pp310-pypy310_pp73-macosx_11_0_arm64.whl (147.0 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

ndindex-1.9.2-pp310-pypy310_pp73-macosx_10_15_x86_64.whl (147.2 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

ndindex-1.9.2-pp39-pypy39_pp73-win_amd64.whl (150.2 kB view hashes)

Uploaded PyPy Windows x86-64

ndindex-1.9.2-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (159.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

ndindex-1.9.2-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (163.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ndindex-1.9.2-pp39-pypy39_pp73-macosx_11_0_arm64.whl (146.9 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

ndindex-1.9.2-pp39-pypy39_pp73-macosx_10_15_x86_64.whl (147.0 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

ndindex-1.9.2-cp313-cp313-win_amd64.whl (158.8 kB view hashes)

Uploaded CPython 3.13 Windows x86-64

ndindex-1.9.2-cp313-cp313-win32.whl (150.9 kB view hashes)

Uploaded CPython 3.13 Windows x86

ndindex-1.9.2-cp313-cp313-musllinux_1_2_x86_64.whl (500.9 kB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

ndindex-1.9.2-cp313-cp313-musllinux_1_2_i686.whl (486.0 kB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.2+ i686

ndindex-1.9.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.0 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

ndindex-1.9.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (484.1 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ndindex-1.9.2-cp313-cp313-macosx_11_0_arm64.whl (160.0 kB view hashes)

Uploaded CPython 3.13 macOS 11.0+ ARM64

ndindex-1.9.2-cp313-cp313-macosx_10_13_x86_64.whl (162.1 kB view hashes)

Uploaded CPython 3.13 macOS 10.13+ x86-64

ndindex-1.9.2-cp312-cp312-win_amd64.whl (159.7 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

ndindex-1.9.2-cp312-cp312-win32.whl (151.5 kB view hashes)

Uploaded CPython 3.12 Windows x86

ndindex-1.9.2-cp312-cp312-musllinux_1_2_x86_64.whl (518.1 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

ndindex-1.9.2-cp312-cp312-musllinux_1_2_i686.whl (501.8 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

ndindex-1.9.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (521.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ndindex-1.9.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (498.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ndindex-1.9.2-cp312-cp312-macosx_11_0_arm64.whl (162.0 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ndindex-1.9.2-cp312-cp312-macosx_10_13_x86_64.whl (164.1 kB view hashes)

Uploaded CPython 3.12 macOS 10.13+ x86-64

ndindex-1.9.2-cp311-cp311-win_amd64.whl (159.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

ndindex-1.9.2-cp311-cp311-win32.whl (151.6 kB view hashes)

Uploaded CPython 3.11 Windows x86

ndindex-1.9.2-cp311-cp311-musllinux_1_2_x86_64.whl (506.3 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

ndindex-1.9.2-cp311-cp311-musllinux_1_2_i686.whl (489.6 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

ndindex-1.9.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (506.1 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ndindex-1.9.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (485.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ndindex-1.9.2-cp311-cp311-macosx_11_0_arm64.whl (161.9 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ndindex-1.9.2-cp311-cp311-macosx_10_9_x86_64.whl (163.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ndindex-1.9.2-cp310-cp310-win_amd64.whl (159.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

ndindex-1.9.2-cp310-cp310-win32.whl (151.8 kB view hashes)

Uploaded CPython 3.10 Windows x86

ndindex-1.9.2-cp310-cp310-musllinux_1_2_x86_64.whl (477.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

ndindex-1.9.2-cp310-cp310-musllinux_1_2_i686.whl (462.1 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

ndindex-1.9.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (475.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ndindex-1.9.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (455.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ndindex-1.9.2-cp310-cp310-macosx_11_0_arm64.whl (162.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ndindex-1.9.2-cp310-cp310-macosx_10_9_x86_64.whl (163.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ndindex-1.9.2-cp39-cp39-win_amd64.whl (160.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

ndindex-1.9.2-cp39-cp39-win32.whl (152.5 kB view hashes)

Uploaded CPython 3.9 Windows x86

ndindex-1.9.2-cp39-cp39-musllinux_1_2_x86_64.whl (483.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

ndindex-1.9.2-cp39-cp39-musllinux_1_2_i686.whl (467.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ i686

ndindex-1.9.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (478.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ndindex-1.9.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (458.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ndindex-1.9.2-cp39-cp39-macosx_11_0_arm64.whl (163.3 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ndindex-1.9.2-cp39-cp39-macosx_10_9_x86_64.whl (164.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

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