Ndenumerate: Difference between revisions
From Master of Neuroscience Wiki
Created page with " = ndenumerate = == Top == Questions to [mailto:davrot@uni-bremen.de David Rotermund] == [https://numpy.org/doc/stable/reference/generated/numpy.ndenumerate.html numpy.ndenumerate] == <syntaxhighlight lang="python">class numpy.ndenumerate(arr)</syntaxhighlight><blockquote>Multidimensional index iterator. Return an iterator yielding pairs of array coordinates and values.</blockquote><syntaxhighlight lang="python">import numpy as np a = np.arange(0, 12).reshape((4, 3))..." |
(No difference)
|
Revision as of 13:27, 17 October 2025
ndenumerate
Top
Questions to David Rotermund
numpy.ndenumerate
class numpy.ndenumerate(arr)
Multidimensional index iterator. Return an iterator yielding pairs of array coordinates and values.
import numpy as np
a = np.arange(0, 12).reshape((4, 3))
print(a)
print()
for index, x in np.ndenumerate(a):
print(index, x)
Output:
[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]
[ 9 10 11]]
(0, 0) 0
(0, 1) 1
(0, 2) 2
(1, 0) 3
(1, 1) 4
(1, 2) 5
(2, 0) 6
(2, 1) 7
(2, 2) 8
(3, 0) 9
(3, 1) 10
(3, 2) 11