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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With