import numpy as np
a=np.arange(1e-10,2e-10,1e-11)
print(len(a))
b=np.arange(0.1,0.2,0.01)
print(len(b))
Value of a is 11 and value of b is 10. Why is that? I've known that arange func is the interval including start but excluding stop.
import numpy as np
a=np.arange(1e-10,2e-10,1e-11)
print(len(a))
b=np.arange(0.1,0.2,0.01)
print(len(b))
Value of a is 11 and value of b is 10. Why is that? I've known that arange func is the interval including start but excluding stop.
Because you are passing an exponentinal, non-integer value to the step parameter of the arange
method. It may cause a not consistent output according to the official documentation.
Try using linspace
method instead. Here is the point from the official documentatin for numpy.arrange
;
When using a non-integer step, such as 0.1, the results will often not be consistent. It is better to use linspace for these cases.