I want to generate a random array of size N which only contains 0 and 1, I want my array to have some ratio between 0 and 1. For example, 90% of the array be 1 and the remainin
Without using numpy, you could do as follows:
import random percent = 90 nums = percent * [1] + (100 - percent) * [0] random.shuffle(nums)