numpy.roll(array, shift, axis = None) : Roll array elements along the specified axis. Basically what happens is that elements of the input array are being shifted. If an element is being rolled first to last-position, it is rolled back to first-position.
array : [array_like][array_like]Input array, whose elements we want to roll shift : [int or int_tuple]No. of times we need to shift array elements. If a tuple, then axis must be a tuple of the same size, and each of the given axes is shifted by the corresponding number. If an int while axis is a tuple of ints, then the same value is used for all given axes. axis : [array_like]Plane, along which we wish to roll array or shift it's elements.
Output rolled array, with the same shape as a.
Original array : [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] Rolling with 1 shift : [[11 0 1 2] [ 3 4 5 6] [ 7 8 9 10]] Rolling with 5 shift : [[ 7 8 9 10] [11 0 1 2] [ 3 4 5 6]] Rolling with 5 shift with 0 axis : [[ 4 5 6 7] [ 8 9 10 11] [ 0 1 2 3]]
These codes won’t run on online-ID. Please run them on your systems to explore the working.
This article is contributed by Mohit Gupta_OMG 😀. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Python - Read blob object in python using wand library
- twitter-text-python (ttp) module - Python
- Python | Merge Python key values to list
- Python | PRAW - Python Reddit API Wrapper
- MySQL-Connector-Python module in Python
- Important differences between Python 2.x and Python 3.x with examples
- Reading Python File-Like Objects from C | Python
- Python | Convert list to Python array
- Python | Index of Non-Zero elements in Python list
- Python | Add Logging to a Python Script
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to Python Libraries
- Python | Sort Python Dictionaries by Key or Value
- Python | Visualizing O(n) using Python
- abs() in Python
- Python if else
- Python vs PHP
- set add() in python
- pow() in Python