Search code examples
numpydtype

numpy.int rounds to wrong value


after updating numpy, numpy.int gives deprecation warnings, so I tried to convert all variables in code to int8 (many of the variables are arrays of 1 and 0). Can someone explain the results from a simple tryout below?

Out[8]: 150.0

np.int8(300/2)
Out[9]: -106

np.int16(300/2)
Out[10]: 150

np.int32(300/2)
Out[11]: 150

Solution

  • The smallest signed number that can be represented in 8 bits is -128 and the largest is 127.numpy doc You can learn more about this [here].2 and here.