I'm certainly a newbie to Python. Hence, I'm struggling to understand the results that the following bit of code gives me for i = 15 and i = 21. In all other cases is does what I expect.
import numpy as np
i_values = []
results = []
results2 = []
for i in range(27):
i_values.append(i)
result = np.int((i*0.02+0.03)*1.e2)
results.append(result)
result2 = (i*0.02+0.03)*1.e2
results2.append(result2)
print i_values
print results
print results2
My question is: Why is the code working for most numbers but fails for certain values of i? I could solve the problem by
result = np.int(np.rint(((i*0.02+0.03)*1.e2))
but I just want to understand why it occurs in the first place.
Thank you in advance.