I want to generate all binary numbers within a specific range, the code I have so far is:
int2binary = {}
largest_number = pow(2,16)
binary = np.unpackbits(np.array([range(largest_number)],dtype=np.uint16).T,axis=1)
As the numbers generated will be higher than an 8-bit binary number can show, I have changed the dtype from np.uint8 (which works) to np.uint16 which then returns the error:
binary = np.unpackbits(np.array([range(largest_number)],dtype=np.uint16).T,axis=1)
TypeError: Expected an input array of unsigned byte data type
How am I able to fix this error? I have looked on the NumpPy website for their datatypes and uint16 is on there so I am not sure why this isn't working.
Update
Using Abhisek Roy's answer, the error is no longer there. However I forgot to add an import part of the code which is giving a new error:
int2binary[i] = b[i]
IndexError: index 1 is out of bounds for axis 0 with size 1
For the loop:
for i in range(largest_number):
int2binary[i] = b[i]