MCPcopy Index your code
hub / github.com/numpy/numpy / ndenumerate

Class ndenumerate

numpy/lib/_index_tricks_impl.py:591–637  ·  view source on GitHub ↗

Multidimensional index iterator. Return an iterator yielding pairs of array coordinates and values. Parameters ---------- arr : ndarray Input array. See Also -------- ndindex, flatiter Examples -------- >>> import numpy as np >>> a = np.arra

Source from the content-addressed store, hash-verified

589
590@set_module('numpy')
591class ndenumerate:
592 """
593 Multidimensional index iterator.
594
595 Return an iterator yielding pairs of array coordinates and values.
596
597 Parameters
598 ----------
599 arr : ndarray
600 Input array.
601
602 See Also
603 --------
604 ndindex, flatiter
605
606 Examples
607 --------
608 >>> import numpy as np
609 >>> a = np.array([[1, 2], [3, 4]])
610 >>> for index, x in np.ndenumerate(a):
611 ... print(index, x)
612 (0, 0) 1
613 (0, 1) 2
614 (1, 0) 3
615 (1, 1) 4
616
617 """
618
619 def __init__(self, arr):
620 self.iter = np.asarray(arr).flat
621
622 def __next__(self):
623 """
624 Standard iterator method, returns the index tuple and array value.
625
626 Returns
627 -------
628 coords : tuple of ints
629 The indices of the current iteration.
630 val : scalar
631 The array element of the current iteration.
632
633 """
634 return self.iter.coords, next(self.iter)
635
636 def __iter__(self):
637 return self
638
639
640@set_module('numpy')

Callers 2

test_basicMethod · 0.90
test_ndindexFunction · 0.90

Calls

no outgoing calls

Tested by 2

test_basicMethod · 0.72
test_ndindexFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…