Python Tutorial - Python Numpy Roll (np.roll)

Опубликовано: 18 Июль 2019
на канале: 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


На этой странице сайта вы можете посмотреть видео онлайн Python Tutorial - Python Numpy Roll (np.roll) длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Python Marathon 18 Июль 2019, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 3,914 раз и оно понравилось 45 зрителям. Приятного просмотра!