python - Left shift inconsistancy -


i asked question yesterday beautifully answered @jezrael

in used:

df = pd.dataframe([[1, 0, 1], [1, 1, 0], [0, 1, 1], [0, 0, 1]])  print (df.t.dot(1 << np.arange(df.shape[0] - 1, -1, -1)))  0    12 1     6 2    11 dtype: int64 

the 1 << np.arange(df.shape[0]) works great df.shape[0] less 30 blows after that. understandable considering data type of int32 or int64. there limit. however, when perform left shift << int operand, returns long , keeps accuracy. how use numpy same result when use 1 << 60?

here's ran:

import numpy np    n in range(0, 61, 10):     = np.arange(n + 1, dtype=int)      pstr = "for n = {:<5d}; 1 << a[-1] = {:<12d}; 1 << n = {:<12d}"      print pstr.format(n, 1 << a[-1], 1 << n)  n = 0    ; 1 << a[-1] = 1           ; 1 << n = 1            n = 10   ; 1 << a[-1] = 1024        ; 1 << n = 1024         n = 20   ; 1 << a[-1] = 1048576     ; 1 << n = 1048576      n = 30   ; 1 << a[-1] = 1073741824  ; 1 << n = 1073741824   n = 40   ; 1 << a[-1] = 256         ; 1 << n = 1099511627776 n = 50   ; 1 << a[-1] = 262144      ; 1 << n = 1125899906842624 n = 60   ; 1 << a[-1] = 268435456   ; 1 << n = 1152921504606846976 

you have convert array of int32 array of python objects:

numbers = np.arange(100,dtype=int) longs = 1 << np.arange(100).astype(object)