Integer Limit Crossed While Performing Bitwise Left Shift Operation In Array
I am creating a numpy array using the bitwise left shift operator. For example, I create array p, where the shape of array is same as that of matrix a i.e. (23,): >>> impo
Solution 1:
Python int and numpy int are not the same... Python supports arbitrary length, whereas numpy is fixed by the type:
numpy.array([1]) << 70
>>> array([64], dtype=int32)
One solution is to use the object dtype:
numpy.array([1], dtype=numpy.object) << 70
>>> array([1180591620717411303424], dtype=object)
And the following will work as expected:
a = numpy.array([1], dtype=numpy.object) << numpy.arange(70)
Looking at the type of the last element, we see that it is a Python int:
type(a[-1])
>>> <class'int'>
Post a Comment for "Integer Limit Crossed While Performing Bitwise Left Shift Operation In Array"