Optimize array unstacking in Numpy and JAX backends (#23388)