I have a following numpy array
a = np.array([[1,2,3,4 ,11, 12,13,14,21,22,23,24,31,32,33,34 ]], dtype=uint8)
when I print a i am getting the following output
[[ 1 2 3 4 11 12 13 14 21 22 23 24 31 32 33 34]]
How can i get the output in binary representation?
for example
[[ 00000001 00000010 00000011 00000100 ...]]
You can use numpy.binary_repr
It takes a number as input and returns its binary representation as a string. You can vectorize this function so that it can take an array as input:
np.vectorize(np.binary_repr)(a, width=8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With