When doing something with a variable with type numpy.int32, the type changes to numpy.int64, which is why I get unexpected values of variables.
For example, with bitwise operations, the result is not the number I need.
>>> import numpy as np >>> (np.int32(335544318)<<6)>>4 1342177272 >>> type((np.int32(335544318)<<6)>>4) <class 'numpy.int64'> If I do not use numpy.int32, I still get 1342177272:
>>> (335544318<<6)>>4 1342177272 If you do the same in JavaScript, you get -8, which I just needed:
> (335544318<<6)>>4 < -8 To get the same in Python, you must manually change the type back to np.int32 after each action:
>>> np.int32(np.int32(335544318)<<6)>>4 -8 I can not understand why this is happening. How can I block the type of a variable so that it retains its 32 bits?
numpyversion? - MaxU(np.int32(335544318)<<6)>>4gives-8- MaxUnp.right_shift(np.left_shift(np.int32(335544318), 6), 4)- MaxU