I have a binary array, and I would like to convert it into a list of integers, where each int is a row of the array.
For example:
from numpy import *
If you like working directly with bitwise math, this one should work pretty well.
def bits2int(a, axis=-1): return np.right_shift(np.packbits(a, axis=axis), 8 - a.shape[axis]).squeeze() bits2int(a) Out: array([12, 4, 7, 15], dtype=uint8)