Median along arbitrary dimensions, fixes #6648