diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-02-18 16:06:21 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-02-18 16:06:21 +0000 |
commit | 82ce0a1e8ccf1b83badb9fac3c2160e5896051b5 (patch) | |
tree | 4232ed30582ae03f94fc873c83303c97930390a2 /numpy/core/numeric.py | |
parent | 0808bca3158c2e3b8828277551082eba144c434a (diff) | |
download | numpy-82ce0a1e8ccf1b83badb9fac3c2160e5896051b5.tar.gz |
ENH: Improve the efficiency of indices
Previously, this special cased something that needed no special case, and did
addition with zero to encourage broadcasting that would happen anyway.
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 |