I want to create a random binary matrix with equal number of ones in each column
Any ideas, how to do in python with numpy for example?
I want to create a random binary matrix with equal number of ones in each column
Any ideas, how to do in python with numpy for example?
Your imposition makes only possible to make matrix with an even number of rows, this may work:
half_n = 10
m = 5
binary_array = np.append(np.ones(half_n, dtype=int), np.zeros(half_n, dtype=int))
list_random = []
for _ in range(m):
binary_random = np.random.choice(binary_array, 2*half_n, replace=False)
list_random.append(binary_random)
matrix = np.matrix(list_random).T