I would like to create a function that takes three arguments (n,m,d) and it should output a matrix with n rows and m columns. The matrix should be populated with values 0 and 1 at random, in order to ensure that you have a density d of ones.
This is what I have come up with so far, just can't seem to work out how to integrate the density variable.
def create_matrix(n, m): count = 1 grid = [] while count <= n: for i in range(m): x = [random.randrange(0,2) for _ in range(m)] grid.append(x) count += 1 return grid