summaryrefslogtreecommitdiff
path: root/numpy/lib/index_tricks.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/index_tricks.py')
-rw-r--r--numpy/lib/index_tricks.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index b04e348b8..314cba120 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -487,7 +487,7 @@ class ndenumerate(object):
def __init__(self, arr):
self.iter = asarray(arr).flat
- def next(self):
+ def __next__(self):
"""
Standard iterator method, returns the index tuple and array value.
@@ -499,11 +499,14 @@ class ndenumerate(object):
The array element of the current iteration.
"""
- return self.iter.coords, self.iter.next()
+ return self.iter.coords, next(self.iter)
def __iter__(self):
return self
+ next = __next__
+
+
class ndindex(object):
"""
An N-dimensional iterator object to index arrays.
@@ -532,7 +535,7 @@ class ndindex(object):
(2, 0, 0)
(2, 1, 0)
- """
+ """
def __init__(self, *shape):
if len(shape) == 1 and isinstance(shape[0], tuple):
shape = shape[0]
@@ -541,16 +544,16 @@ class ndindex(object):
def __iter__(self):
return self
-
+
def ndincr(self):
"""
Increment the multi-dimensional index by one.
This method is for backward compatibility only: do not use.
"""
- self.next()
+ next(self)
- def next(self):
+ def __next__(self):
"""
Standard iterator method, updates the index and returns the index tuple.
@@ -560,9 +563,11 @@ class ndindex(object):
Returns a tuple containing the indices of the current iteration.
"""
- self._it.next()
+ next(self._it)
return self._it.multi_index
+ next = __next__
+
# You can do all this with slice() plus a few special objects,
# but there's a lot to remember. This version is simpler because