Home > Enterprise >  Sort an array of floats. Result must be floats not list
Sort an array of floats. Result must be floats not list

Time:01-20

I would like to sort a very large array of floats. When I use sorted, the result is a list. However, I want a new array of floats.

Here is a short example:

    import numpy as np
    xmaxp = np.array([25.0, 5.0, 1.0],dtype=float)
    xmaxp_sorted = sorted(xmaxp)

CodePudding user response:

as everybody else mentioned, use numpy sort method :

import numpy as np

xmaxp = np.array([25.0, 5.0, 1.0], dtype=float)
xmaxp_sorted = np.sort(xmaxp)

result :

[ 1.  5. 25.]
<class 'numpy.ndarray'>

CodePudding user response:

I think you can use np.array

np.array(xmaxp_sorted)
  •  Tags:  
  • Related