Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Python p.ravel question

Programming


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 2 Weeks Ago
1Brajesh 1Brajesh is offline
Registered User
 
Join Date: Aug 2017
Last Activity: 4 September 2017, 2:51 PM EDT
Posts: 10
Thanks: 9
Thanked 0 Times in 0 Posts
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?

Code:
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.
Sponsored Links
    #2  
Old Unix and Linux 2 Weeks Ago
apmcd47 apmcd47 is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 21 September 2017, 6:23 AM EDT
Posts: 235
Thanks: 8
Thanked 58 Times in 55 Posts
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

Code:
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
Code:
ix = np.random.choice(range(vocab_size), p=p.ravel())

returns a list of vocab_size elements taken at random from p into ix?
The Following User Says Thank You to apmcd47 For This Useful Post:
1Brajesh (2 Weeks Ago)
Sponsored Links
    #3  
Old Unix and Linux 2 Weeks Ago
1Brajesh 1Brajesh is offline
Registered User
 
Join Date: Aug 2017
Last Activity: 4 September 2017, 2:51 PM EDT
Posts: 10
Thanks: 9
Thanked 0 Times in 0 Posts
hmm...could be
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
A straightforward Python question. wisecracker Programming 4 04-18-2017 02:32 PM
Question about Strings in Python mohtashims Shell Programming and Scripting 1 05-17-2016 04:39 PM
Python question cstsang Shell Programming and Scripting 1 07-07-2014 05:26 AM
Capslock and Python Question mrm5102 UNIX for Dummies Questions & Answers 0 06-30-2014 03:26 PM
NEWBIE QUESTION: python 3 or 2.6.x guptaxpn Programming 2 12-15-2008 11:04 PM



All times are GMT -4. The time now is 08:22 AM.