bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / lib / _index_tricks_impl / IndexExpression
class
numpy.lib._index_tricks_impl:IndexExpression
source: build-install/usr/lib/python3.14/site-packages/numpy/lib/_index_tricks_impl.py :723
Signature
class IndexExpression ( maketuple ) Members
Summary
A nicer way to build up index tuples for arrays.
Extended Summary
For any index combination, including slicing and axis insertion, a[indices] is the same as a[np.index_exp[indices]] for any array a. However, np.index_exp[indices] can be used anywhere in Python code and returns a tuple of slice objects that can be used in the construction of complex index expressions.
Parameters
maketuple: boolIf True, always returns a tuple.
Notes
You can do all this with slice plus a few special objects, but there's a lot to remember and this version is simpler because it uses the standard array indexing syntax.
Examples
import numpy as np np.s_[2::2] np.index_exp[2::2]✓
np.array([0, 1, 2, 3, 4])[np.s_[2::2]]
✓See also
- s_
Predefined instance without tuple conversion:
s_ = IndexExpression(maketuple=False). Theindex_expis another predefined instance that always returns a tuple:index_exp = IndexExpression(maketuple=True).
Aliases
-
numpy.lib._index_tricks_impl.IndexExpression