You can use the resample() function of the scikit-learn module. The function resamples arrays or sparse matrices in a consistent way. You can specify the "number of samples" and "with or without replacement" as parameters.
sklearn.utils.resample(*arrays, replace=True, n_samples=None, random_state=None, stratify=None)
Here is an example using "with replacement":
from sklearn.utils import resample
y = [1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1]
y_sampled = resample(y, replace=True, n_samples=5)
print(y_sampled)
Here is an example using "without replacement":
from sklearn.utils import resample
y = [1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1]
y_sampled = resample(y, replace=False, n_samples=5)
print(y_sampled)