Python p.ravel question

Hi,

I'm trying to decipher some python code located here:
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy * GitHub

I'm unable to understand what line 75 is doing?

ix = np.random.choice(range(vocab_size), p=p.ravel())

Anyone know what this might mean? I've looked at the documentation for p.ravel located here:

numpy.ravel � NumPy v1.13 Manual

and I still feel lost !

Could anyone explain this to me in layman terms, I'm no expert in programming or math.

I've never used numpy but it looks as though the ravel function is flattening an n-dimensional array into a 1D array such that

p = [ [a, b, c] [d, e, f] [g, h, i] ]
p.ravel()
[ a, b, c, d, e, f, g, h, i ]

Without reading up on numpy, is it possible that

ix = np.random.choice(range(vocab_size), p=p.ravel())

returns a list of vocab_size elements taken at random from p into ix ?

1 Like

hmm...could be