-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: arange behaves poorly on complex numbers #10332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Si 8000 gn up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
These proposals, for
|
I somewhat like the look of a general error ;). I am serious though, if you have multiple good options, its likely hopelss to define something here. It does not seem useful to me (in the sense of transparent for a reader), except for |
In the case when option 3 does not error, all of the other options are equivalent to it (and this is sufficient to be consistent with real numbers). So arguably 3 is worth doing. |
Althought without a step argument, I can think of no clear meaning for the following (shown with current results): >>> np.arange(0, 4 + 4j)
array([ 0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j])
>>> np.arange(0, 4 + 0j)
array([]) I suppose that since the current behaviour makes no sense at all, we should switch it to an error now, and consider allowing it in future. |
Erroring on |
This comment has been minimized.
This comment has been minimized.
Shedding some light on the original code - I think it was intended to mean Of course, |
This comment has been minimized.
This comment has been minimized.
The c_len.imag == 0 solution seems good. I still think that for anything except for pretty much exact integers that might be a bit random (tiny error or scaling might cause exact 0 to be missed?), so in that sense I am not quite sure that simply forcing linspace isn't just as good. OTOH, for purely imaginary or real numbers it sounds most reasonable. |
Until the behavior is fixed, we should change the documentation to exclude complex args for
I'll mention this issue in the PR so it will show up here; that will remind us when the code is fixed that the restrictions in the doc can be removed. |
As noted in issue numpy#10332, arange with complex start, stop, or step returns an empty array. Until the code is changed, specify that these args can only be integer or real.
For some reason, it deliberately computes len as (c14792d)
which for real-only values, gives
0
.I think a better approach would be to use one of
ceil(abs(c_len))
- has semantics "use the circle centered atstart
and passing throughend
" as the end pointceil(c_len.real)
- has semantics "use the projection ofend
onto the linestart + k*step
as the endpoint"above with
assert c_len.imag == 0
- requires thatend
lies on that line, but prone to rounding errorProject
step
onto the line betweenstart
andend
, and use that insteadI like the look of 2 and 4
The text was updated successfully, but these errors were encountered: