I want to generate a random n x n binary matrix using NumPy, where:
- each value is either
0or1 - every row sums up to
1 - every column sums up to
1
For example, a valid matrix might be
[[1 0 0]
[0 0 1]
[0 1 0]]
while an invalid one is
[[1 0 0]
[0 0 1]
[0 0 1]]
I tried doing the following, but I couldn't figure out how to shuffle the values in each column using a unique index. How do I generate a matrix that adheres to the above constraints?
N = 10
a = np.zeros((N,N))
a[0,:] = 1