[Numpy-discussion] ndrange, like range but multidimensiontal
allanhaldane at gmail.com
Wed Oct 10 14:21:00 EDT 2018
On 10/10/18 12:34 AM, Eric Wieser wrote:
> One thing that worries me here - in python, |range(...)| in essence
> generates a lazy |list| - so I’d expect |ndrange| to generate a lazy
> |ndarray|. In practice, that means it would be a duck-type defining an
> |__array__| method to evaluate it, and only implement methods already
> present in numpy.
Isn't that what arange is for?
It seems like there are two uses of python3's range: 1. creating a 1d
iterable of indices for use in for-loops, and 2. with list(range) can be
used to create a sequence of integers.
Numpy can extend this in two directions:
* ndrange returns an iterable of nd indices (for for-loops).
* arange returns an 1d ndarray of integers instead of a list
The application of for-loops, which is more niche, doesn't need
ndarray's vectorized properties, so I'm not convinced it should return
an ndarray. It certainly seems simpler not to return an ndarray, due to
the dtype question.
arange on its own seems to cover the need for a vectorized version of range.
More information about the NumPy-Discussion