I need to generate a random binary matrix with dimensions m x n where all their rows are different among themselves. Using numpy I tried
import numpy as np import random n = 512 m = 1000 a = random.sample(range(0, 2**n), m) a = np.array(a) a = np.reshape(a, (m, 1)) np.unpackbits(a.view(np.uint8), axis=1)
But it is not suitable for my case because n > 128 and m > 1000. So, the code above generates only rows with at most 62 elements. Could you help me, please?
import numpy as np m = 1000 n = 512 while True: a = np.random.choice([0, 1], size=(m, n)) if len(np.unique(a, axis=0)) == m: break
Answered By – Tonechas
Answer Checked By – Willingham (BugsFixing Volunteer)