Quick select algorithm for ndarrays