Generate random array of 0 and 1 with a specific ratio

后端 未结 4 2143
孤城傲影
孤城傲影 2021-02-19 06:09

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

4条回答
  •  执念已碎
    2021-02-19 06:16

    You could use a binomial distribution:

    np.random.binomial(n=1, p=0.9, size=[1000])
    

提交回复
热议问题