[Python-ideas] Float range class

Andrew Barnert abarnert at yahoo.com
Sat Jan 10 04:29:08 CET 2015

On Jan 9, 2015, at 14:36, Guido van Rossum <guido at python.org> wrote:

> (Although the actual signature of linspace gives me a headache. :-)

I'm assuming you're not talking about the rested and dtype args (which the stdlib wouldn't need), but rather the fact that endpoint changes the meaning of num (you effectively generate num+1 points and discard the last, instead of generating num points).

I've stumbled over that before, and helped other people with it. But the other way around would be confusing just as often. And the confusion wouldn't be flagged as quickly as it is in numpy (broadcasting mismatched arrays is an error; zipping mismatched sequences is not). And of course it would be a gratuitous incompatibility between the stdlib and numpy.

All of this implies that there's probably some better way to specify half-open ranges for linspace that nobody has thought of yet. Hopefully someone can think of it now. :)

Or, failing that, maybe we just don't need half-open linspace in the stdlib. You can always do linspace(0, 1, 5+1)[:-1] or, if you want the other, linspace(0, 1, 5)[:-1]. Either way, what you're asking for is explicit and obvious. And if linspace is a sequence-like view akin to range, this doesn't cost anything. And it's even briefer than using the endpoint argument (especially since in real life you almost always use it as a keyword arg).

Since Chris seems to have a better intuition than me on how you're usually thinking when you need linspace, hopefully he can chime in on whether this would be intuitive enough, or if we need an actual solution.

More information about the Python-ideas mailing list