0

below code give me

0.1

0.2

0.30000000000000004

0.4

0.5

0.6

0.7000000000000001

0.8

0.9

1.0

and I don't know why 0.3 and 0.7 come out that way.

import numpy as np

for i in np.arange(0.1,1.1,0.1):
    print(i)

1 Answers1

0

Check the docs for np.arange:

When using a non-integer step, such as 0.1, the results will often not be consistent. It is better to use numpy.linspace for these cases.

Jussi Nurminen
  • 2,257
  • 1
  • 9
  • 16