How to reverse an array?

Hey everyone. I need your help. This is my vector [1,2,3,4,5] . I want to invert in a way that the last value comes first and so on. I used the list function but that is on applicable to Python’s built-in List and not working on my array. Please provide me with a solution that reverses my array.

1 Like

Hello @safa, the flip() function of NumPy can help you reverse your array with just one line of code, this function simply reverses the order of the elements along a specified axis. Here is an example code which uses this function:

Hey there! the reverse() function is a useful Python built-in function for reversing the order of elements in a list. However, if you have a NumPy array, you cannot directly apply the reverse() function to it. To use the reverse() function on a NumPy array, you must first convert the array to a list and then apply the reverse() function.

Note: The ‘reverse()’ function modifies the original list in place and does not return a new list.