Make reshaper more robust and more compact using np.ndindex