summaryrefslogtreecommitdiff
path: root/numpy/lib/index_tricks.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-01-26 21:42:01 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-01-26 21:42:01 +0000
commitf6d28d03b06dd15c9523a84047d6bec8b987b2d9 (patch)
tree5b7f9f2354773006b16d39351829d63d94a3b7c5 /numpy/lib/index_tricks.py
parent5da0b20fd90045f35b2b76e3ddff4f1c6c48908a (diff)
downloadnumpy-f6d28d03b06dd15c9523a84047d6bec8b987b2d9.tar.gz
Simplify the ndenumerate class by exposing coords and index from flat iterator. Simple cosmetic changes to ffts.
Diffstat (limited to 'numpy/lib/index_tricks.py')
-rw-r--r--numpy/lib/index_tricks.py21
1 files changed, 2 insertions, 19 deletions
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index 0e625d3fa..604bd6059 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -243,7 +243,6 @@ c_.__doc__ = """Translates slice objects to concatenation along the second axis.
#col = concatenator(-1,1)
-
class ndenumerate(object):
"""
A simple nd index iterator over an array.
@@ -258,31 +257,15 @@ class ndenumerate(object):
(1, 1) 4
"""
def __init__(self, arr):
- arr = asarray(arr)
- self.iter = enumerate(arr.flat)
- self.ashape = arr.shape
- self.nd = arr.ndim
- self.factors = [None]*(self.nd-1)
- val = self.ashape[-1]
- for i in range(self.nd-1,0,-1):
- self.factors[i-1] = val
- val *= self.ashape[i-1]
+ self.iter = asarray(arr).flat
def next(self):
- res = self.iter.next()
- indxs = [None]*self.nd
- val = res[0]
- for i in range(self.nd-1):
- indxs[i] = val / self.factors[i]
- val = val % self.factors[i]
- indxs[self.nd-1] = val
- return tuple(indxs), res[1]
+ return self.iter.coords, self.iter.next()
def __iter__(self):
return self
-
# You can do all this with slice() plus a few special objects,
# but there's a lot to remember. This version is simpler because
# it uses the standard array indexing syntax.