reversed_arr = arr[::-1]

gives a reversed view into the original array arr. Any changes made to the original array arr will also be immediately visible in reversed_arr. The underlying data buffers for arr and reversed_arr are shared, so creating this view is always instantaneous, and does not require any additional memory allocation or copying for the array contents.

See also, this discussion on NumPy views: How do I create a view onto a NumPy array?


Possible solutions to performance problems regarding views

Are you re-creating the view more often than you need to? You should be able to do something like this:

arr = np.array(some_sequence)
reversed_arr = arr[::-1]

do_something(arr)
look_at(reversed_arr)
do_something_else(arr)
look_at(reversed_arr)

I'm not a numpy expert, but this seems like it would be the fastest way to do things in numpy. If this is what you are already doing, I don't think you can improve on it.

Answer from steveha on Stack Overflow
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-invert-numpy-array
How to invert NumPy array
Line 3: Then, we create a NumPy one-dimensional array to perform the inversion. Line 4: Now, we call np.flip() with the arr array as the argument. This function returns a new array with the elements reversed, which we store in the variable flipped_arr.
Top answer
1 of 8
342
reversed_arr = arr[::-1]

gives a reversed view into the original array arr. Any changes made to the original array arr will also be immediately visible in reversed_arr. The underlying data buffers for arr and reversed_arr are shared, so creating this view is always instantaneous, and does not require any additional memory allocation or copying for the array contents.

See also, this discussion on NumPy views: How do I create a view onto a NumPy array?


Possible solutions to performance problems regarding views

Are you re-creating the view more often than you need to? You should be able to do something like this:

arr = np.array(some_sequence)
reversed_arr = arr[::-1]

do_something(arr)
look_at(reversed_arr)
do_something_else(arr)
look_at(reversed_arr)

I'm not a numpy expert, but this seems like it would be the fastest way to do things in numpy. If this is what you are already doing, I don't think you can improve on it.

2 of 8
95
a[::-1]

only creates a view, so it's a constant-time operation (and as such doesn't take longer as the array grows). If you need the array to be contiguous (for example because you're performing many vector operations with it), ascontiguousarray is about as fast as flipud/fliplr:


Code to generate the plot:

import numpy
import perfplot


perfplot.show(
    setup=lambda n: numpy.random.randint(0, 1000, n),
    kernels=[
        lambda a: a[::-1],
        lambda a: numpy.ascontiguousarray(a[::-1]),
        lambda a: numpy.fliplr([a])[0],
    ],
    labels=["a[::-1]", "ascontiguousarray(a[::-1])", "fliplr"],
    n_range=[2 ** k for k in range(25)],
    xlabel="len(a)",
)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-reverse-a-numpy-array
Reverse a Numpy Array - Python - GeeksforGeeks
September 20, 2025 - For 1D arrays, it behaves like numpy.flip(). For 2D arrays, it reverses rows.
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ numpy โ€บ python-numpy-exercise-6.php
NumPy: Reverse an array - w3resource
August 29, 2025 - Write a NumPy program to reverse an array (the first element becomes the last). Sample Solution: Python Code: # Importing the NumPy library with an alias 'np' import numpy as np # Creating an array 'x' using arange() function with values from 12 to 37 (inclusive) x = np.arange(12, 38) # Printing the original array 'x' containing values from 12 to 37 print("Original array:") print(x) # Reversing the elements in the array 'x' and printing the reversed array print("Reverse array:") x = x[::-1] print(x) Sample Output: Original array: [12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37] Reverse array: [37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12] Explanation: In the above code - np.arange(12, 38): Creates a one-dimensional NumPy array with a range of integers starting from 12 (inclusive) up to, but not including, 38.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ numpy โ€บ methods โ€บ flip
NumPy flip()
The flip() method reverses the order of the elements in an array. The flip() method reverses the order of the elements in an array. Example import numpy as np # create an array array1 = np.array([0, 1, 2, 3, 4]) # flip the elements of array1 array2 = np.flip(array1) print(array2) # Output: ...
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ third-party โ€บ numpy โ€บ flip
Python Numpy flip() - Reverse Array Order | Vultr Docs
November 18, 2024 - The flip() function in Python's NumPy library offers a straightforward and efficient way to reverse the order of array elements along a specified axis.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ what are the different ways to reverse a numpy array?
What are the Different Ways to Reverse a NumPy Array? - Scaler Topics
May 4, 2023 - As illustrated in the following example, this approach does not destroy the original numpy array : ... The reverse() function is a built-in Python technique that allows us to immediately reverse a list.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.flip.html
numpy.flip โ€” NumPy v2.4 Manual
>>> import numpy as np >>> A = np.arange(8).reshape((2,2,2)) >>> A array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) >>> np.flip(A, 0) array([[[4, 5], [6, 7]], [[0, 1], [2, 3]]]) >>> np.flip(A, 1) array([[[2, 3], [0, 1]], [[6, 7], [4, 5]]]) >>> np.flip(A) array([[[7, 6], [5, 4]], [[3, 2], [1, 0]]]) >>> np.flip(A, (0, 2)) array([[[5, 4], [7, 6]], [[1, 0], [3, 2]]]) >>> rng = np.random.default_rng() >>> A = rng.normal(size=(3,4,5)) >>> np.all(np.flip(A,2) == A[:,:,::-1,...]) True
Find elsewhere
๐ŸŒ
w3resource
w3resource.com โ€บ numpy โ€บ manipulation โ€บ flip.php
NumPy: numpy.flip() function - w3resource
March 24, 2023 - The numpy.flip() function is used to reverse the order of elements in an array along the given axis.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.1 โ€บ reference โ€บ generated โ€บ numpy.flip.html
numpy.flip โ€” NumPy v2.1 Manual
>>> import numpy as np >>> A = np.arange(8).reshape((2,2,2)) >>> A array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) >>> np.flip(A, 0) array([[[4, 5], [6, 7]], [[0, 1], [2, 3]]]) >>> np.flip(A, 1) array([[[2, 3], [0, 1]], [[6, 7], [4, 5]]]) >>> np.flip(A) array([[[7, 6], [5, 4]], [[3, 2], [1, 0]]]) >>> np.flip(A, (0, 2)) array([[[5, 4], [7, 6]], [[1, 0], [3, 2]]]) >>> rng = np.random.default_rng() >>> A = rng.normal(size=(3,4,5)) >>> np.all(np.flip(A,2) == A[:,:,::-1,...]) True
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ reverse an array in python โ€“ 10 examples
Reverse an Array in Python - 10 Examples - AskPython
January 16, 2024 - The flip() method in the NumPy module reverses the order of a NumPy array and returns the NumPy array object.
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-reverse-numpy-array
Reverse NumPy Arrays In Python
May 16, 2025 - The simplest way to reverse a NumPy array is by using the np.flip() function. This Python built-in method allows you to reverse an array along any specified axis.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python numpy reverse array
Python NumPy Reverse Array - Spark By {Examples}
March 27, 2024 - You can reverse a NumPy array using basic slicing notation. For instance, arr[::-1] uses slicing notation to create a view of the array with a step of -1, effectively reversing the order of elements in the array.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-reverse-a-numpy-array
Python | Reverse a numpy array - GeeksforGeeks
September 16, 2022 - The numpy.flip() function reverses the order of array elements along the specified axis, preserving the shape of the array.
๐ŸŒ
Finxter
blog.finxter.com โ€บ 5-best-ways-to-reverse-a-numpy-array-in-python
5 Best Ways to Reverse a NumPy Array in Python โ€“ Be on the Right Side of Change
February 20, 2024 - The slicing syntax arr_2d[::-1, ::-1] indicates that we want to reverse the array along both the row and column axes. Method 1: numpy.flip(). Itโ€™s a universal method provided by NumPy and can be used for arrays with any number of dimensions. However, it does create a copy of the array which ...
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ numpy โ€บ numpy reverse array
How to Reverse Array in NumPy | Delft Stack
February 2, 2024 - Another function that can be used to reverse an array is the numpy.flipud() function. The numpy.flipud() function flips the elements of the array upside down. The numpy.flipud() function takes the array as an argument and returns the reverse ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ numpy flip() function in python
NumPy flip() Function in Python - Spark By {Examples}
March 27, 2024 - In NumPy, the flip() function is used to reverse the order of array elements along a specified axis. The shape of the array is preserved, but the elements
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.flipud.html
numpy.flipud โ€” NumPy v2.2 Manual
Reverse the order of elements along axis 0 (up/down). For a 2-D array, this flips the entries in each column in the up/down direction.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ numpy
NumPy: Flip array (np.flip, flipud, fliplr) | note.nkmk.me
June 25, 2019 - Using numpy.flip() you can flip the NumPy array ndarray vertically (up-down) or horizontally (left-right). There are also numpy.flipud() specialized for vertical flipping and numpy.fliplr() specialize ...
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ 2.2 โ€บ reference โ€บ generated โ€บ numpy.flip.html
numpy.flip โ€” NumPy v2.2 Manual
>>> import numpy as np >>> A = np.arange(8).reshape((2,2,2)) >>> A array([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]) >>> np.flip(A, 0) array([[[4, 5], [6, 7]], [[0, 1], [2, 3]]]) >>> np.flip(A, 1) array([[[2, 3], [0, 1]], [[6, 7], [4, 5]]]) >>> np.flip(A) array([[[7, 6], [5, 4]], [[3, 2], [1, 0]]]) >>> np.flip(A, (0, 2)) array([[[5, 4], [7, 6]], [[1, 0], [3, 2]]]) >>> rng = np.random.default_rng() >>> A = rng.normal(size=(3,4,5)) >>> np.all(np.flip(A,2) == A[:,:,::-1,...]) True