Descargar el Código: patreon.com/pythonmaraton
Join Patreon: patreon.com/pythonmaraton
^Downloadable code & more! np.roll
So here we have a random array A that I created earlier.
np.roll is a numpy function that allows you to shift arrays by as many indexes as you desire. Let’s jump into this example and show you how this works.
np.roll(A,1) Now the 1 is in the 10 spot the 10 is in the three spot and so on… As you can see everything has been shifted over to the right by one.
Next let’s see A again. And lets do np.roll but this time we will shift it by two.
Now you might be wondering Why is this useful?
Let me go ahead and show you an application.
Suppose you have an array of points and you want to approximate the derivative or in other words the step at each point. np.roll can help you do that.
We just take A and subtract all the points shifted to the right by one or in other words A - np.roll(A,1)
Now make sure to ignore the first term. If we are finding the difference in 25 points then there will only be 24 differences .
The first term is the difference between the first and last point so it is not significant step. So I like to use the (A - np.roll(A,1))[1:]
So there you have it that is how to use numpy’s np.roll function in python.
Please check out some of my other python videos and don’t forget to hit subscribe :D
This is a Python anaconda tutorial for help with coding, programming, or computer science. These are short python videos dedicated to troubleshooting python problems and learning Python syntax. For more videos see Python Help playlist by Rylan Fowers.
✅Subscribe: https://www.youtube.com/channel/UCub4...
📺Channel: https://www.youtube.com/channel/UCub4...
▶️Watch Latest Python Content: https://www.youtube.com/watch?v=myCPg...
▶️Watch Latest Other Content: https://www.youtube.com/watch?v=2YfQs...
🎵Theme Music: https://www.bensound.com/royalty-free...
#PythonMarathon #LearnPython #PythonTutorial
Auf dieser Seite können Sie das Online-Video Python Tutorial - Python Numpy Roll (np.roll) mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Python Marathon 18 Juli 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 3,914 Mal angesehen und es wurde von 45 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!