I am looking for an efficient way of turning
a=np.array([[0,1,1,0],
[0,1,1,1]])
into
b=np.array([[0b0110],
[0b0111]])
or into
b=np.array([[6],
[7]])
The only thing I found so far is np.packbits but this only works with 8bit numbers. However my arrays have shape of around (20e6,20)
I could of course do it by hand:
a=np.array([[0,1,1,0],[0,1,1,1]])
c=2**np.arange(np.shape(a)[-1])[::-1]
b=a.dot(c)
b
Out: array([6, 7])
But I assume that there is a faster way. Especially if the conversion directly to a binary array is possible.
Thanks for help!