0

I need to generate an array in numpy (there are N numbers).

There are only two kinds of element in this array, for example: 3.0 and -3.0. The probability of occurring 3.0 is 0.4, and the probability of occurring -3.0 is 0.6.

How to generate such an array?

dodolong
  • 795
  • 1
  • 8
  • 14

1 Answers1

3

This will do the job:

n=10
np.random.choice([3,-3],n,p=[0.4,0.6])
Miriam Farber
  • 17,600
  • 14
  • 58
  • 72