Inconsistent arange behaviour with different int types
See original GitHub issueGiven this code:
import numpy as np
np.arange(1,1,0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero
Obviously step 0 is an invalid input for creating a range. So the division error is understandable, but might be more explicit. What surprised me, was the following behaviour:
np.arange(np.int64(1),1,0)
__main__:1: RuntimeWarning: invalid value encountered in long_scalars
>>> array([], dtype=int64)
The code is as wrong as before, but now instead of throwing any error, it just returns an empty list. Shouldn’t it throw exactly the same error as above? An error explicitly stating, that a range with a step of 0 can’t be specified?
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Inconsistent behavior in np.arange? - python - Stack Overflow
It states that the "interval does not include stop value, except in some cases where step is not an integer and floating point...
Read more >TypedDict incompatible with `RequestData = dict` type in httpx
post parameter accepting an object of type RequestData , with RequestData = dict . Actual behaviour. Argument of type "MyDictionary" cannot be ...
Read more >Numpy Arange Floating Point Inconsistency - ADocLib
This post is about how OpenScad type-casts a floating point number to a string(str()) or I would expect extra significant digits to be...
Read more >The neural computation of inconsistent choice behavior - Nature
Many previous studies have identified several brain regions—primarily the ventral striatum (vStr), the ventromedial prefrontal cortex (vmPFC) ...
Read more >Type checking errors - Free Pascal
Error: Incompatible types: got ”arg1” expected ”arg2” ... The compiler expects an expression of type integer, but gets a different type.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Now
np.int32
andnp.int64
produce aValueError
whileint
andnp.int
produceZeroDivisionError
. This is unfortunately still inconsistent.@melissawm if we have a test that runs into the issue, no (i.e. raises the error probably). Otherwise, I cannot say without checking it closer.
That said, I suspect it is long fixed, sorry, I can’t do a full check right now.