Home > Enterprise >  How to reverse the elements in numpy.ndarray Python
How to reverse the elements in numpy.ndarray Python

Time:11-28

I have a numpy.ndarray in Python has the following elements e.g[[-0.85] [ 0.95]]. How can I reverse it so it can be [ [ 0.95][-0.85]]. Keep in mind that the length always two but for sure the values are changing.

<class 'numpy.ndarray'>
[[-0.85]
[ 0.95]]

CodePudding user response:

numpy.flip() should do the job

array = numpy.flip(array)

returns

[[ 0.95] [-0.85]]

CodePudding user response:

You can do this by using flip() function.

import numpy as np    
l=[12,45,10,78,100]
m=np.flip(l)
print(m)

Alternatively, you can also go this approach.

m=l[::-1]
print(m)

You can find something informative here.

Happy Coding!

  • Related