I'd like to sort a two-dimensional array
, based on for instance second column (if the rows are sorted based on from low to high all the other rows with the same index of this column get shuffled based on the new order in the second column). It is easy to implement it in python.
d=np.array([[ 0.98807639, 0.17761071, 0.02576818],
[ 0.90376256, 0.91729465, 0.42179004],
[ 0.73540802, 0.38300233, 0.99331352],
[ 0.99808863, 0.83837682, 0.16279504],
[ 0.34154819, 0.6701753 , 0.85538715],
[ 0.15164261, 0.2007122 , 0.80347646]])
data=np.array(sorted(d, key=lambda l:l[1]))
data=np.array([[ 0.98807639, 0.17761071, 0.02576818],
[ 0.15164261, 0.2007122 , 0.80347646],
[ 0.73540802, 0.38300233, 0.99331352],
[ 0.34154819, 0.6701753 , 0.85538715],
[ 0.99808863, 0.83837682, 0.16279504],
[ 0.90376256, 0.91729465, 0.42179004]])
but I need to do the same procedure in cython
, in order to improve the speed of my code since numpy module is very slow. In c
there is function qsort
but I don't know how it should be implemented for 2d array, since I am not very familiar with pointer structure in c
. How it should be done in cython to also speed up the code considerably for big arrays?