# Reverse an array - Python
Data Science for Political and Social Phenomena
Author: Guillaume Redoulès

# Reverse an array

## Using lists

Python provides an iterator to reverse an array reversed()

you can use it this way :

    arr = list(range(5))
    print(f'Initial array : {arr}\n')

    reversed_arr = list(reversed(arr))
    print(f'Reversed array : {reversed_arr}')

    Initial array : [0, 1, 2, 3, 4]

    Reversed array : [4, 3, 2, 1, 0]

## Using numpy

If you are using numpy you can reverse an array by creating a view on the array:

    import numpy as np
    arr = np.arange(5)
    print(f'Initial array : {arr}\n')

    reversed_arr = arr[::-1]
    print(f'Reversed array : {reversed_arr}')

    Initial array : [0 1 2 3 4]

    Reversed array : [4 3 2 1 0]

### Find an error or bug? Have a suggestion?

Everything on this site is avaliable on GitHub. Head on over and submit an issue. You can also message me directly by email.