Optimized get dist to use numpy array indexing