-2

What is the type of output here?:

H2 = np.random.rand(*H1.shape) < p   ## p= 0.60    60%
Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331

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
  • 221,503
  • 14
  • 230
  • 353
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
  • 31,927
  • 11
  • 74
  • 85