diff options
author | Marten van Kerkwijk <mhvk@astro.utoronto.ca> | 2017-02-19 10:09:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-19 10:09:14 -0500 |
commit | eda7009cf14a9b8e9b03ddd5a8ec369646c8525d (patch) | |
tree | 9f896c628ea3f512d5a05790f6ca0d1bababd487 /numpy/core/numeric.py | |
parent | aba10bb5829caee63a20251a226d8cb716ec1125 (diff) | |
parent | 82ce0a1e8ccf1b83badb9fac3c2160e5896051b5 (diff) | |
download | numpy-eda7009cf14a9b8e9b03ddd5a8ec369646c8525d.tar.gz |
Merge pull request #8629 from eric-wieser/speedup-indices
ENH: Improve the efficiency of indices
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index b90b0a9c9..97d19f008 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2089,15 +2089,12 @@ def indices(dimensions, dtype=int): """ dimensions = tuple(dimensions) N = len(dimensions) - if N == 0: - return array([], dtype=dtype) + shape = (1,)*N res = empty((N,)+dimensions, dtype=dtype) for i, dim in enumerate(dimensions): - tmp = arange(dim, dtype=dtype) - tmp.shape = (1,)*i + (dim,)+(1,)*(N-i-1) - newdim = dimensions[:i] + (1,) + dimensions[i+1:] - val = zeros(newdim, dtype) - add(tmp, val, res[i]) + res[i] = arange(dim, dtype=dtype).reshape( + shape[:i] + (dim,) + shape[i+1:] + ) return res |