This needs a comment on the logic going on there.

I think the idea is that if the index is slice or int, you need to swap the axes, but if it's fancy indexing, the output shape comes from the index arrays and doesn't need to be swapped.