How do I generate a list of length N with random 0 and 1 values , but with a given number of 1\'s put randomly in the list.
For example, I want a list of 10
Using numpy
import numpy as np
from random import shuffle
A = np.ones(7, dtype=np.int) // [1 1 1 1 1 1 1] and data-type as integer
B = np.zeros(3, dtype=np.int) // [0 0 0] and data-type as integer
C = np.concatenate((A, B), axis = 0) // [1 1 1 1 1 1 1 0 0 0]
shuffle(C) // [1 0 0 1 1 1 1 0 1 1]
print C