Ndindex: Difference between revisions

From Master of Neuroscience Wiki
Created page with "== Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.ndindex.html numpy.ndindex] == <syntaxhighlight lang="python">class numpy.ndindex(*shape)[source]</syntaxhighlight><blockquote>An N-dimensional iterator object to index arrays. Given the shape of an array, an ndindex instance iterates over the N-dimensional index of the array. At each iteration a tuple of indices is returned, the last dimensio..."
 
No edit summary
 
Line 1: Line 1:
== Top ==
Questions to [mailto:davrot@uni-bremen.de David Rotermund]
Questions to [mailto:davrot@uni-bremen.de David Rotermund]



Latest revision as of 16:48, 17 October 2025

Questions to David Rotermund

numpy.ndindex

class numpy.ndindex(*shape)[source]

An N-dimensional iterator object to index arrays. Given the shape of an array, an ndindex instance iterates over the N-dimensional index of the array. At each iteration a tuple of indices is returned, the last dimension is iterated over first.

import numpy as np

for index in np.ndindex((3, 2, 1)):
    print(index)

Output:

(0, 0, 0)
(0, 1, 0)
(1, 0, 0)
(1, 1, 0)
(2, 0, 0)
(2, 1, 0)