Generation of matrix with sum 1 for each row and at least 1 assignment for each column

82 Views Asked by At

How can I create a binary matrix where each column sums to 1 and in the columns is >= 1? I need to build n*m matrices to perform assignments in an algorithm.

1

There are 1 best solutions below

3
vighub On

I don't know if this is what you are looking for, but an identity matrix solve your request if the number of rows is equal to the number of columns.

With numpy, you can achieve that

import numpy as np

rows = 3
matrix = np.eye(rows)

The result is then :
[[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]]