skillfed

ndindex

A Python library for manipulating indices of ndarrays.

ndindex v1.10.1 3.6M downloads/30d#2,549 on PyPI
Permissive license MIT AGING released

What it is and what it does

ndindex is a library for working with array indices as first-class objects. Instead of treating slices, integers, ellipses, and other index types as separate, incompatible objects, ndindex wraps them in a uniform API so you can inspect, transform, and reason about them programmatically. It guarantees that all transformations match actual array indexing semantics—meaning if you reduce or manipulate an index through ndindex, the result will behave identically to real array behavior.

The library is useful when you need to reason about array shapes and indices without materializing arrays, optimize index expressions, or verify that an index operation would succeed before executing it. It handles the full range of indexing: simple slices, negative indices, steps, ellipses, boolean masks, integer arrays, and nested tuples. For operations where array shape is known, ndindex can reduce complex indices to simpler equivalent forms.

Use it for:

  • Canonicalize and simplify slice objects to their minimal equivalent form for a given array shape
  • Compute the output shape of an array after indexing without materializing the array itself
  • Check whether an index operation would produce an empty result before executing it
  • Validate and transform user-provided indices in array-processing libraries or frameworks
  • Implement index-aware optimizations in array computation engines

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

ndindex provides a uniform API for representing and manipulating NumPy array indices—slices, integers, ellipses, None, arrays, and tuples—with semantics guaranteed to match NumPy's behavior.

Yes, if you work with array indexing logic in libraries, frameworks, or tools that need to reason about indices without executing them. The library is well-maintained within its scope, has no dependencies, and carries no security vulnerabilities. However, the aging maintenance status (268 days since last release) means you should verify active support if you depend on frequent updates or encounter edge cases.

Install

ndindex on PyPI

pip

pip install ndindex

uv

uv add ndindex

poetry

poetry add ndindex

Installing ndindex

Before you install

Medium install friction due to platform-specific wheels across multiple Python versions and architectures, but no runtime dependencies. Last release was 268 days ago; maintenance status is aging.

License in practice

MIT license is permissive; you may use, modify, and distribute ndindex freely in commercial and private projects with minimal restrictions.

Quickstart

from ndindex import Slice, Tuple

# Canonicalize a slice over a shape
result = Slice(-2, 10, 3).reduce(5)
print(result)  # Slice(3, 4, 1)

# Compute resulting shape after indexing
shape = Tuple(0, slice(0, 10)).newshape((10, 20))
print(shape)  # (10,)

Requires Python >= 3.9

Verify before relying

  • Whether the library handles all edge cases in array indexing semantics beyond the documented scope
  • Performance characteristics when working with complex multi-dimensional indices

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.9)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance aging — 268 days since the last release
First released
Downloads 3,635,994/month — #2,549 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: ndindex-1.10.1-cp310-cp310-macosx_10_9_x86_64.whl; ndindex-1.10.1-cp310-cp310-macosx_11_0_arm64.whl; ndindex-1.10.1-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; ndindex-1.10.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; ndindex-1.10.1-cp310-cp310-musllinux_1_2_aarch64.whl; ndindex-1.10.1-cp310-cp310-musllinux_1_2_x86_64.whl; ndindex-1.10.1-cp310-cp310-win32.whl; ndindex-1.10.1-cp310-cp310-win_amd64.whl; ndindex-1.10.1-cp311-cp311-macosx_10_9_x86_64.whl; ndindex-1.10.1-cp311-cp311-macosx_11_0_arm64.whl; ndindex-1.10.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; ndindex-1.10.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; ndindex-1.10.1-cp311-cp311-musllinux_1_2_aarch64.whl; ndindex-1.10.1-cp311-cp311-musllinux_1_2_x86_64.whl; ndindex-1.10.1-cp311-cp311-win32.whl; ndindex-1.10.1-cp311-cp311-win_amd64.whl; ndindex-1.10.1-cp312-cp312-macosx_10_13_x86_64.whl; ndindex-1.10.1-cp312-cp312-macosx_11_0_arm64.whl; ndindex-1.10.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; ndindex-1.10.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Operating System :: OS IndependentProgramming Language :: Python :: 3

Tags

numpy array indexing manipulationslice canonicalizationindex transformation libraryndarray index semanticsarray slicing utilities
numpy-indexingarray-manipulation

More Mathematics packages