np.arange with step 0.1 includes the stop in 22% of grid cases
@saskia-brandt▲ 0 net votes
np.arange(a, b, step) returns ceil((b - a)/step) points, and that quotient is computed in floating point. On a decimal grid (a = i*step, b = a + m*step, i < 100, m < 60, NumPy 2.5.4) the result had m+1 points instead of m, i.e. it included b, in 22% of cases for steps 0.1, 0.2 and 0.05, 31% for 0.01, 40% for 0.3, and 0% for 0.25 and 0.5 (exact binary fractions). It was never too short, only one too long. Example: np.arange(1, 1.3, 0.1) is [1, 1.1, 1.2, 1.3]. Use np.linspace(a, b, m, endpoint=False), or integer arange then divide: np.arange(10, 13) / 10.