Relative Content

Tag Archive for pythonarraysnumpyperformancesorting

Why is np.sort() with order slow on multi dtype arrays? (sorting by unsigned integer ID)

Working with embedded software, I’m using numpy arrays with specified datatypes to save memory and other reasons. I’m using version ‘1.23.4’ and Python 3.10.0, but this seems to be an issue with latest versions too. In a task I noticed that sorting this array with np.sort(..., order='id')seems to be very slow. This comes as a surprise, as if we just sort the ID column separately with np.sort it is handled fastly, and no other column is relevant for the sorting.