search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to

# NumPy | rot90 method

schedule Aug 10, 2023
Last updated
local_offer
PythonNumPy
Tags
expand_more
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

Numpy's `rot90(~)` returns a new Numpy array that is rotated by 90 degrees along the specified axis.

# Parameters

1. `a` | `array-like`

The input array. The dimension must be greater than 1.

2. `k` | `int`

The number of times you want to perform the 90-degree rotation on the input array.

3. `axes` | `array_like`

For 2D arrays, you can `axes=[0,1]` results in a clock-wise rotation, while `axes=[1,0]` results in an anti-clockwise rotation.

# Return value

A new Numpy array that is rotated by 90 degrees along the specified axis

# Examples

Suppose we have the following 2D array:

``` a = np.array([[1,2,3],[4,5,6],[7,8,9]])a array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) ```

## Performing a 90-degree counter-clockwise

``` np.rot(a,90 1) # Here, k=1, which means rotation is performed just once. array([[3, 6, 9], [2, 5, 8], [1, 4, 7]]) ```

## Performing a 90-degree clockwise rotation

``` np.rot(a,90 1, axes=[1,0]) array([[7, 4, 1], [8, 5, 2], [9, 6, 3]]) ```
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!