Also, this will be pretty slow for large matrices.  This line is a possible candidate for cythonization: it would be a pretty easy utility routine to write for CSR matrices, especially if you take advantage of the cython sorting functions already implemented in the neighbors-related code.