python: convert ascii character to boolean array -


i have character. want represent ascii value numpy array of booleans. works, seems contorted. there better way?

bin_str = bin(ord(mychar)) bool_array = array([int(x)>0 x in list(bin_str[2:])], dtype=bool) 

for

mychar = 'd' 

the desired resulting value bool_array is

array([ true,  true, false, false,  true, false, false], dtype=bool) 

this more or less same thing:

>>> import numpy np >>> mychar = 'd' >>> np.array(list(np.binary_repr(ord(mychar), width=4))).astype('bool') array([ true,  true, false, false,  true, false, false], dtype=bool) 

is less contorted?


Comments