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
Sur cette page du site, vous pouvez voir la vidéo en ligne Python Tutorial - Python Numpy Roll (np.roll) durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Python Marathon 18 juillet 2019, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 3,914 fois et il a aimé 45 téléspectateurs. Bon visionnage!