Python: np.sort VS array.argsort()
I figure out why it didn't work with np.sort().
I misused the structured array function.
With the following dtype, I have created my array with the following line:
Data = np.zeros((78000,11),dtype=dtype2)
I though that I had to create 1 row for each structured data. WRONG ! The right line is: Data = np.zeros((78000,1),dtype=dtype2)
I'm facing something strange, the function sort and the attribut argsort don't give me the same results.
I have a Data array (CFD results) with the following structure:
dtype([('nodenumber', '<f8'), ('    x-coordinate', '<f8'), ('    y-coordinate', '<f8'), ('    z-coordinate', '<f8'), ('        pressure', '<f8'), ('  total-pressure', '<f8'), ('      x-velocity', '<f8'), ('      y-velocity', '<f8'), ('      z-velocity', '<f8'), ('     temperature', '<f8'), ('total-temperature\n', '<f8')])

So, each column contains one measured parameters at one point. I would like to sort the array by increasing 'z-coordinate' AND of course move line by line during the sorting (1line <=> 1 point and coresponding values).
I tried this function:
Data_sorted = np.sort(Data,axis=0,kind='mergesort',order='    z-coordinate')
It returns me a sorted array but the lines are completely messed up. For example, the previous point 1 has now a completely different z-coordinate. I don't want that.
Then I used this function (The 3rd column is the z-coordinate) :
order = Data[:, 3].argsort(kind='mergesort')
Data_sorted = np.take(Data, order, axis=0)
And... it works ! The array has been sorted by increasing z-coordinate and the points are still coherent (it seems, at least).
Do you have an idea why these both similar function provide different results ?
Because in a 2nd step, I will need to do something like that:
Data_sorted = np.sort(Data,axis=0,kind='mergesort',order=('    z-coordinate','    y-coordinate'))\=