def bool_to_bitarray(value):
 value = value.flat
 bit_no = 7
 byte = 0
 bytes = []
 for v in value:
  if v:
   byte |= (1 << bit_no)
  if (bit_no == 0):
   bytes.append(byte)
   bit_no = 7
   byte = 0
  else:
   bit_no -= 1
 if (bit_no != 7):
  bytes.append(byte)
 return struct_pack(u'{}B'.format(len(bytes)), *bytes)

def bool_to_bitarray ( value ) : value = value . flat bit_no = 7 byte = 0 bytes = [ ] for v in value : if v : byte |= ( 1 << bit_no ) if ( bit_no == 0 ) : bytes . append ( byte ) bit_no = 7 byte = 0 else : bit_no -= 1 if ( bit_no != 7 ) : bytes . append ( byte ) return struct_pack ( u'{}B' . format ( len ( bytes ) ) , * bytes )
converts a numpy boolean array to a bit array .