Python Tutorial - Python Numpy Roll (np.roll)

Published: 18 July 2019
on channel: Python Marathon
3,914
45

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


On this page of the site you can watch the video online Python Tutorial - Python Numpy Roll (np.roll) with a duration of hours minute second in good quality, which was uploaded by the user Python Marathon 18 July 2019, share the link with friends and acquaintances, this video has already been watched 3,914 times on youtube and it was liked by 45 viewers. Enjoy your viewing!