Python Forum
Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python
#3
Not a numpy expert here, but this seems to reverse all the axis simultaneously
import numpy as np
 
random_array = np.round(10 * np.random.rand(5, 4, 4))
sorted_array = np.sort(random_array,axis=1)
 
a = sorted_array.reshape(sorted_array.size)
reversed_array = a[::-1].reshape(sorted_array.shape)

print('Sorted Array:')
print(sorted_array,'\n')
print('Reversed Array:')
print(reversed_array)
Jeremy7 likes this post
Reply


Messages In This Thread
RE: Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python - by Gribouillis - Feb-22-2021, 08:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python code to calculate mean of an array of numbers using numpy viren 3 249 May-29-2024, 04:49 PM
Last Post: Gribouillis
  Writing a cycle to find the nearest point from the array Tysrusko 0 249 May-10-2024, 11:49 AM
Last Post: Tysrusko
  This result object does not return rows. It has been closed automatically dawid294 6 1,687 Mar-30-2024, 03:08 AM
Last Post: NolaCuriel
  Elegant way to apply each element of an array to a dataframe? sawtooth500 7 662 Mar-29-2024, 05:51 PM
Last Post: deanhystad
  Concatenate array for 3D plotting armanditod 1 365 Mar-21-2024, 08:08 PM
Last Post: deanhystad
  Convert numpy array to image without loading it into RAM. DreamingInsanity 7 6,179 Feb-08-2024, 09:38 AM
Last Post: paul18fr
  How Write Part of a Binary Array? Assembler 1 466 Jan-14-2024, 11:35 PM
Last Post: Gribouillis
  How is pandas modifying all rows in an assignment - python-newbie question markm74 1 822 Nov-28-2023, 10:36 PM
Last Post: deanhystad
  Loop over an an array of array Chendipeter 1 667 Nov-28-2023, 06:37 PM
Last Post: deanhystad
  How to remove some elements from an array in python? gohanhango 9 1,716 Nov-28-2023, 08:35 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020