Below code displays from 12.01 till 16.01. But shouldn't it display only till 16.00?
import numpy as np
for i in np.arange(12.01, (16.01), 0.01):
print(float('{num:0.2f}'.format(num=i)))
Below code displays from 12.01 till 16.01. But shouldn't it display only till 16.00?
import numpy as np
for i in np.arange(12.01, (16.01), 0.01):
print(float('{num:0.2f}'.format(num=i)))
From the numpy.arange documentation:
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.
So linspace
might be more appropriate for your case
If you want 400 evenly spaced numbers from 12.01 to 16:
np.linspace(12.01, 16, num=400)