A Random Walk & Monte Carlo Simulation || Python Tutorial || Learn Python Programming

///A Random Walk & Monte Carlo Simulation || Python Tutorial || Learn Python Programming

A Random Walk & Monte Carlo Simulation || Python Tutorial || Learn Python Programming

FavoriteLoadingAdd to favorites

A random walk is a process where each step is chosen randomly. This technique has many applications. In this video we solve a random walk puzzle using Monte Carlo simulations and the random module in Python.

➢➢➢➢➢➢➢➢➢➢
To learn Python, you can watch our playlist from the beginning:

➢➢➢➢➢➢➢➢➢➢
We recommend:
Python Cookbook, Third edition from O’Reilly

The Mythical Man Month – Essays on Software Engineering & Project Management

Shop Amazon Used Textbooks – Save up to 90%

➢➢➢➢➢➢➢➢➢➢
Subscribe to Socratica:

To support more videos from Socratica, visit
Socratica Patreon

Socratica Paypal

We also accept Bitcoin! 🙂
Our address is: 1EttYyGwJmpy9bLY2UcmEqMJuBfaZ1HdG9

➢➢➢➢➢➢➢➢➢➢
Python instructor: Ulka Simone Mohanty
Written & Produced by Michael Harrison
FX by Andriy Kostyuk

source

By |2019-11-06T23:47:53+00:00November 6th, 2019|Python Video Tutorials|43 Comments

43 Comments

  1. Socratica November 6, 2019 at 11:47 pm - Reply

    It's official! The Socratica Python Kickstarter was a success! Thank you to all of our supporters. Because of you, many more Python videos coming soon!! 💜🦉

  2. Felipe Vargas November 6, 2019 at 11:47 pm - Reply

    I didnt understand the answer. Why the walk close to 50% is the correct?

  3. Electromorphous November 6, 2019 at 11:47 pm - Reply

    So nobody's gonna talk about why even number of walks has a higher chance of being fewer blocks away from home?

  4. bluidguy November 6, 2019 at 11:47 pm - Reply

    Neat!

  5. Jerry Gundecker November 6, 2019 at 11:47 pm - Reply

    Could this woman be related to Captain Kirk's computer?

  6. Alpha TEDS November 6, 2019 at 11:47 pm - Reply

    nice video editing 🙂

  7. rasha yahya November 6, 2019 at 11:47 pm - Reply

    This channel became my one of my favorite YouTube channels

  8. Socratica November 6, 2019 at 11:47 pm - Reply

    HEEELLLLLLP! http://bit.ly/PythonKickstarter

    DEADLINE SUNDAY OCT 20th

  9. Muhammad Junaid Ali November 6, 2019 at 11:47 pm - Reply

    Mashallah

  10. Socratica November 6, 2019 at 11:47 pm - Reply

    We're halfway there. We still need your help! Support Socratica Python Kickstarter: http://bit.ly/PythonKickstarter

  11. Socratica November 6, 2019 at 11:47 pm - Reply

    Support what you love! Socratica has a Kickstarter to make more Python: http://bit.ly/PythonKickstarter

  12. Arman Iskaliyev November 6, 2019 at 11:47 pm - Reply

    She is pretty hot

  13. Vit. C. November 6, 2019 at 11:47 pm - Reply

    fox "x" first zero for "y" second zero. I you have only one zero python is fucked up. Best regards from perl.

  14. Rahul Sharma November 6, 2019 at 11:47 pm - Reply

    how can it be solved mathematically?

  15. Solrac V November 6, 2019 at 11:47 pm - Reply

    # As a Generator
    import random

    def random_walk_gen():

    x, y = 0, 0

    while True:

    yield x, y

    dx, dy = random.choice([(0, 1), (0, -1), (1,0), (-1,0)])

    x, y = x + dx, y + dy

  16. Solrac V November 6, 2019 at 11:47 pm - Reply

    import random

    import matplotlib.pyplot as plt

    def random_walk(n):

    x, y = 0, 0

    for i in range(n):

    dx, dy = random.choice([(0, 1), (0, -1), (1,0), (-1,0)])

    plt.plot([x, x+dx],[y, y+dy], 'k-')

    x += dx

    y += dy

    random_walk(5000)

    plt.show()

  17. Roger Lie November 6, 2019 at 11:47 pm - Reply

    Yes, but how do you write a silly walk program in Python?

  18. Tho H. Ho November 6, 2019 at 11:47 pm - Reply

    This looks like something from 1998.

  19. Ian Grant November 6, 2019 at 11:47 pm - Reply

    I will never use any programming language whose semantics depend upon how my teletype interprets ASCII 0x09! 😂

  20. Muhammad Latif November 6, 2019 at 11:47 pm - Reply

    if she is not a robot then she is an angel.

  21. Mübin Icyer November 6, 2019 at 11:47 pm - Reply

    YouTube recommended this video to me randomly.

  22. helo void November 6, 2019 at 11:47 pm - Reply

    tsundere!

  23. Nihar Kashyap November 6, 2019 at 11:47 pm - Reply

    Subbed within 2 minutes into the video!

  24. Ajeet Kumar November 6, 2019 at 11:47 pm - Reply

    This is so fascinating, she is my programmer teacher now

  25. F Harrison November 6, 2019 at 11:47 pm - Reply

    for walk_length in range(1,31):
    why do we eliminate the possibility of 0? like for example, someone walk 2 blocks, one walk north and one walk south then the distance is 0?

  26. Naji Ould Es. Ahmed November 6, 2019 at 11:47 pm - Reply

    What a delivery! Blessed be…!!

  27. pwnk November 6, 2019 at 11:47 pm - Reply

    These are the videos I like most about python, do not stop uploading that content please, thank you very much!

  28. El-Andalussi November 6, 2019 at 11:47 pm - Reply

    The voice is freezing …

  29. Skeptic Sam November 6, 2019 at 11:47 pm - Reply

    this robot is my new python teacher

  30. MeshMN November 6, 2019 at 11:47 pm - Reply

    5:05 So is this prejudicial view of Monte Carlo the entire view of Socratica or just the tasteless individual you chose as a spokesperson? Regardless, prejudice is in poor form especially on a so-called educational forum – you lost a subscriber.

  31. Maric November 6, 2019 at 11:47 pm - Reply

    its like a strategy game briefing 😀

  32. Rico Cordova November 6, 2019 at 11:47 pm - Reply

    Nice intro video, but your code would never pass a linter. 😉

    For people new to Python (or coding, in general), don't write your methods like this. These are fine for examples, but if you are actually writing a project, you should be more explicit with your variable names. PEP8 is a fantastic guideline for coding style. It's targeting Python, but most of it can be applied generally.

    I would also recommend following the Zen of Python. You can read it by entering a Python interpreter and run "import this". Run the following in a terminal.

    python -c "import this"

    Always run a linter against your code before finishing. There are linters for all languages. A linter simply runs a check against style rules. For instance, if your variable names are correct, or lines are too long, or your inheritance structure isn't correct, etc. It won't check for runtime errors. It only checks for style and clarity. Both of which are important – especially if you work in a team. For Python, I recommend pylint.

  33. M҉i҉ Ro November 6, 2019 at 11:47 pm - Reply

    Could someone please explain why we're looking at the 50% threshold? I don't get the explanation at 4:50

  34. Parth Pandey November 6, 2019 at 11:47 pm - Reply

    33 ans

  35. Mike Lezhnin November 6, 2019 at 11:47 pm - Reply

    Me: ah, you mean this?
    random_walk = lambda n: sum(numpy.array([[0,1],[1,0],[0,-1],[-1,0]])[ramdom.randint(0,3)] for i in range(n))

    P.S. I actually think it can be written shorter but I'm too lazy to think how to do that.

  36. Marc Smithsonian November 6, 2019 at 11:47 pm - Reply

    No not everything is in order it shows how stupid unreliable and messed up python is. Random function called for pairs vs single variable produced diferennt output, distribution and distances…. so good luck with such "language" where " randomness" depends on algi implementation…

  37. HAV Architecture November 6, 2019 at 11:47 pm - Reply

    I LOVE YOU! excellent presentation!

  38. mrmuranga November 6, 2019 at 11:47 pm - Reply

    please make more python videos..these videos are very informative

  39. Bush Ninja November 6, 2019 at 11:47 pm - Reply

    So you have to run to walk?

  40. Duke Skookum November 6, 2019 at 11:47 pm - Reply

    As for the "even numbers get you closer" thing:

    Since the direction of the steps is evenly distributed, in the even case, we can expect the number of steps going up to be the same to those going down. But in the odd case, we can expect the number of steps in one direction to be one larger than the other, leading us further away from the origin. The same is true for the left/right dimension. This phenomenon should be less and less noticeable, as we increase the number of steps.

  41. Duke Skookum November 6, 2019 at 11:47 pm - Reply

    I think that the problem statement is not clear.

    The average length of a 22 block random walk is about 5.28. This is higher than 4.

    On the other hand, for 12 blocks, the average length is about 3.86.

    And for 13 blocks, the average is about 4.33.

    So the longest random walk you can take so that , on average, you end up at at most 4 blocks from the origin ist 12.

    The soulution of 22 is for a different problem: "What is the longest random walk you can take, so that more than half of the time you end up at at most 4 blocks away from the origin?"

  42. Anubhav Yadav November 6, 2019 at 11:47 pm - Reply

    excellent video

  43. Tarik Al-Hoshan November 6, 2019 at 11:47 pm - Reply

    What happens if you fail to do the exercise?

Leave A Comment

*