-2

What is the type of output here?:

H2 = np.random.rand(*H1.shape) < p   ## p= 0.60    60%
Russia Must Remove Putin
  • 337,988
  • 84
  • 391
  • 326

2 Answers2

2
In [489]: x = np.random.rand(2,3)
In [490]: x
Out[490]: 
array([[ 0.09070037,  0.27653004,  0.14790416],
       [ 0.38391008,  0.1477435 ,  0.63524601]])

to find elements that are less than .5:

In [491]: x<.5   
Out[491]: 
array([[ True,  True,  True],
       [ True,  True, False]], dtype=bool)
hpaulj
  • 201,845
  • 13
  • 203
  • 313
0

Your question was "What is the type of output here". The output will be a boolean (True or False) since it's comparing the result of np.random.rand(*H1.shape) with p. If p is bigger than np.random.rand(*H1.shape) H2 will be True. Otherwise H2 will be False(if np.random.rand(*H1.shape) is equal or smaller than p).

Taku
  • 28,570
  • 11
  • 65
  • 77