3

I was studying this link and this is the code .

 U1 = np.random.rand(*H1.shape) < p # first dropout mask

Why does it fail when I try to do this?

import numpy
numpy.random.rand(*1) < 2 

I understand that the rand() function takes in a number which is why I am confused that the code is supposed to work.

Lafexlos
  • 7,618
  • 5
  • 38
  • 53
aceminer
  • 4,089
  • 9
  • 56
  • 104

1 Answers1

11

The * unpacks a tuple into multiple input arguments. The code is creating a random matrix the same shape as H1 using the shape attribute (which is a tuple) as the dimension inputs to np.random.rand.

You can do this with any tuple

np.random.rand(*(2,3))     # The same as np.random.rand(2,3)
# Creates a 2 x 3 array

You are trying to unpack an integer which is going to fail.

Suever
  • 64,497
  • 14
  • 82
  • 101