You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add step parameter to linspace (or endpoint parameter to arange) (Trac #2176) #630
There's no simple way to make a sequence based on step size that includes both endpoints. For instance, to produce the sequence [1.0, 1.1, 1.2, 1.3, 1.4, 1.5], you'd have to do something clunky like:
linspace(1.0, 1.5, (1.5-1.0)/0.1+1)
or
arange(1.0, 1.5+0.01, 0.1)
it would be more convenient if you could just say
linspace(1.0, 1.5, step=0.1)
or maybe
arange(1.0, 1.5, 0.1, endpoint=True)
Of course, step could not be specified at the same time as num.
Reacted by Peter Pablo, pinplex, Niranjan Thakurdesai, William Mayner, Trevor Avant and Clement Etienam
I'd say the difference between linspace and arange is exactly that: obtaining a range by specifying number of steps or step size, respectively. For that reason, I favor your last proposal (extending the arange interface).
I'd have said the main difference between them is that linspace is all
about floats and arange is all about ints. Of course you can override this,
but that's what they do by default and that's what motivates the other
differences. So I think adding a new argument to linspace is the most
natural, but really both have their place and aren't redundant. These will
still return different things:
linspace(0, 10, step=1)
arange(0, 10, include_endpoint=True)
because the first will be a float array and the second an int array.
We should think whether a similar step argument makes sense for logspace.
On 23 Jan 2013 02:19, "SjoerdOptLand" [email protected] wrote:
I'd say the difference between linspace and arange is exactly that:
obtaining a range by specifying number of steps or step size, respectively.
For that reason, I favor your last proposal (extending the arange
interface).
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/630#issuecomment-12589259.
I am not sure you can resolve this really. Giving an endpoint argument to arange is OK for integer aranges, but considering how unsafe arange is for inexact types, it seems to just giving another reason to use it for something it should not be used for. The whole example arange(1.0, 1.5, 0.1, endpoint=True) is dangerous, and the endpoint argument gives an illusion that it will end with 1.5, when it might be ending with 1.6.
As for allowing a step argument to linspace, I don't see how you would not just add the existing pitfalls of arange to linspace (and avoiding those is most of the point of linspace).
Or would there be some method of actually guaranteeing to give the expected result for these cases? In that case it would be a good addition.
For linspace with a step= argument, I suppose we could impose the semantics
that the space must be evenly divisible by the given step size. Then we
can check this, and if it's almost true (within some relative precision),
we force it to be exactly true, and if it's definitely not true, we error
out. That should allow us to finesse the inexactness thing while also
avoiding the usual problems of trying to guess whether to round or not...?
I am not sure you can resolve this really. Giving an endpoint argument to
arange is OK for integer aranges, but considering how unsafe arange is for
inexact types, it seems to just giving another reason to use it for
something it should not be used for. The whole example arange(1.0, 1.5,
0.1, endpoint=True) is dangerous, and the endpoint argument gives an
illusion that it will end with 1.5, when it might be ending with 1.6.
As for allowing a step argument to linspace, I don't see how you would not
just add the existing pitfalls of arange to linspace (and avoiding those is
most of the point of linspace).
Or would there be some method of actually guaranteeing to give the
expected result for these cases? In that case it would be a good addition.
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/630#issuecomment-12604377.
Please excuse me bringing up this old issue. As the proposed PR was not merged, was there by now added some similar functionality? (seberg@c012ea2 was not applied, was it?)
Reacted by pinplex, Nikita Khlestov and William Mayner
Activity
SjoerdOptLand commentedon Jan 23, 2013
I'd say the difference between linspace and arange is exactly that: obtaining a range by specifying number of steps or step size, respectively. For that reason, I favor your last proposal (extending the arange interface).
njsmith commentedon Jan 23, 2013
I'd have said the main difference between them is that linspace is all
about floats and arange is all about ints. Of course you can override this,
but that's what they do by default and that's what motivates the other
differences. So I think adding a new argument to linspace is the most
natural, but really both have their place and aren't redundant. These will
still return different things:
linspace(0, 10, step=1)
arange(0, 10, include_endpoint=True)
because the first will be a float array and the second an int array.
We should think whether a similar step argument makes sense for logspace.
On 23 Jan 2013 02:19, "SjoerdOptLand" [email protected] wrote:
seberg commentedon Jan 23, 2013
I am not sure you can resolve this really. Giving an endpoint argument to arange is OK for integer aranges, but considering how unsafe arange is for inexact types, it seems to just giving another reason to use it for something it should not be used for. The whole example
arange(1.0, 1.5, 0.1, endpoint=True)is dangerous, and theendpointargument gives an illusion that it will end with1.5, when it might be ending with1.6.As for allowing a step argument to linspace, I don't see how you would not just add the existing pitfalls of arange to linspace (and avoiding those is most of the point of linspace).
Or would there be some method of actually guaranteeing to give the expected result for these cases? In that case it would be a good addition.
njsmith commentedon Jan 23, 2013
Hmm, yeah, good points :-)
For linspace with a step= argument, I suppose we could impose the semantics
that the space must be evenly divisible by the given step size. Then we
can check this, and if it's almost true (within some relative precision),
we force it to be exactly true, and if it's definitely not true, we error
out. That should allow us to finesse the inexactness thing while also
avoiding the usual problems of trying to guess whether to round or not...?
On Wed, Jan 23, 2013 at 8:38 AM, seberg [email protected] wrote:
seberg commentedon Jan 23, 2013
Check gh-2945 for a stab at adding such a (convenience) functionality, which enforces that an integer number of steps can be safely determined.
ENH: Add safe step argument to linspace
PeterPablo commentedon Jul 27, 2017
Please excuse me bringing up this old issue. As the proposed PR was not merged, was there by now added some similar functionality? (seberg@c012ea2 was not applied, was it?)