I am trying to generate a binary matrix of numbers with m rows and n columns. Each row must sum to <=p and >=q and each column must have an even spread (if permitted) or similar to rows <=j, >=k a min and max range.
import numpy as np
def randbin(M,N,P):
return np.random.choice([0, 1], size=(M,N), p=[P, 1-P])
MyMatrix = randbin(200,7,0.5)
However this gives me some rows with all zeros and rows with all ones. Is there an efficient way of achieving this solution?
Aucun commentaire:
Enregistrer un commentaire