[~/scratch]
|4> !cat random-mesh.txt
0.3 0.3 21
0 0 10
0 0.3 11
0.3 0.6 22
0 0.6 12
0.6 0.3 31
0.3 0 20
0.6 0.6 32
0.6 0 30
[~/scratch]
|5> scrambled_nodes = np.loadtxt('random-mesh.txt')
# Note! Put the "faster" column before the "slower" column!
[~/scratch]
|6> i = np.lexsort([scrambled_nodes[:, 1], scrambled_nodes[:, 0]])
[~/scratch]
|7> sorted_nodes = scrambled_nodes[i]
[~/scratch]
|8> sorted_nodes
array([[ 0. , 0. , 10. ],
[ 0. , 0.3, 11. ],
[ 0. , 0.6, 12. ],
[ 0.3, 0. , 20. ],
[ 0.3, 0.3, 21. ],
[ 0.3, 0.6, 22. ],
[ 0.6, 0. , 30. ],
[ 0.6, 0.3, 31. ],
[ 0.6, 0.6, 32. ]])
Then carry on with the reshape()ing as before. If the grid points that "ought to be the same" are not actually identical, then you may end up with some problems, e.g. if you had "0.300000000001 0.0 20.0" as a row, but all of the other "x=0.3" rows had "0.3", then that row would get sorted out of order. You would have to clean up the grid coordinates a bit first.
--
Robert Kern