@@ -966,15 +966,22 @@ def __iter__(self) -> Iterator[ChunkProjection]:
966966
967967 # handle advanced indexing arrays orthogonally
968968 if self .is_advanced :
969- # N.B., numpy doesn't support orthogonal indexing directly as yet,
970- # so need to work around via np.ix_. Also np.ix_ does not support a
971- # mixture of arrays and slices or integers, so need to convert slices
972- # and integers into ranges.
973- chunk_selection = ix_ (chunk_selection , self .chunk_shape )
974-
975- # special case for non-monotonic indices
976- if not is_basic_selection (out_selection ):
977- out_selection = ix_ (out_selection , self .shape )
969+ # NumPy can handle a single array-indexed dimension directly,
970+ # which preserves full slices and avoids an
971+ # unnecessary advanced-indexing copy. Integer-indexed
972+ # dimensions still need the ix_ path for downstream squeezing.
973+ # Example: we skip `ix_` for array[:, :, [1, 2, 3]]
974+ n_array_dims = sum (isinstance (sel , np .ndarray ) for sel in chunk_selection )
975+
976+ if n_array_dims > 1 or self .drop_axes :
977+ # N.B., numpy doesn't support orthogonal indexing directly
978+ # for multiple array-indexed dimensions, so we need to
979+ # convert the orthogonal selection into coordinate arrays.
980+ chunk_selection = ix_ (chunk_selection , self .chunk_shape )
981+
982+ # special case for non-monotonic indices
983+ if not is_basic_selection (out_selection ):
984+ out_selection = ix_ (out_selection , self .shape )
978985
979986 is_complete_chunk = all (p .is_complete_chunk for p in dim_projections )
980987 yield ChunkProjection (chunk_coords , chunk_selection , out_selection , is_complete_chunk )
0 commit comments