jeudi 25 novembre 2021

Generate a random symmetric binary matrix in Python

I've looked for several question on SO but couldn't find this or figure it out how to do it. I want to generate a random symmetric binary matrix (n x n), from a given n.

Examples (n=3):

    0 0 1         0 0 1 
    1 0 1   or    0 0 0
    1 0 0         1 0 0
              

I also need the main diagonal to be zero. I know how to do it later, but in case one already want to implement it in an optimal code...




Aucun commentaire:

Enregistrer un commentaire