[Python-Dev] range objects in 3.x

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Sep 27 16:52:55 CEST 2011


On Mon, Sep 26, 2011 at 9:25 PM, Steven D'Aprano <steve at pearwood.info> wrote:
..
> The audience for numpy is a small minority of Python users, and they tend to
> be more sophisticated. I'm sure they can cope with two functions with
> different APIs <wink>
>
> While continuity of API might be a good thing, we shouldn't accept a poor
> API just for the sake of continuity. I have some criticisms of the linspace
> API.

+1

In addition to Steven's criticisms of numpy.linspace(), I would like a
new function to work with types other than float.  It certainly makes
sense to have range-like functionality for fractions and decimal
floats, but also I often find a need to generate a list of equally
spaces dates or datetime points.  It would be nice if a new function
would allow start and stop to be any type that supports subtraction
and whose differences support division by numbers.

Also, in terms of implementation, I don't think we'll gain anything by
copying numpy code because linspace(start, stop, num) is effectively
just

arange(0, num) * step + start

where step is (stop-start)/(num-1).  This works because numpy arrays
(produced by arange()) support linear algebra and we are not going to
copy that.


More information about the Python-Dev mailing list