Fancy indexing with integer arrays, meshgrid selection, and np.ix_().
Fancy indexing allows selecting arbitrary matrix elements by passing arrays of row and column coordinates. `np.ix_` generates open cross-product index meshes.
Passing list `[0, 2, 4]` to `arr[[0, 2, 4]]` is like calling specific student roll numbers to stand up, in any custom order.
`np.ix_([r0, r1], [c0, c1])` constructs an open 2D mesh to extract the Cartesian cross-product subarray.
sub = matrix[np.ix_([0, 2], [1, 3])]matrix[[0, 1], [0, 1]] # Selects points (0,0) and (1,1), NOT a 2x2 box!matrix[np.ix_([0, 1], [0, 1])] # Selects the full 2x2 cross-product submatrixPassing two 1D coordinate arrays pairs them as points `(r[i], c[i])`. Use `np.ix_` for rectangular sub-grids.
Solve the objective below using NumPy vectorized syntax
Create `arr = np.array([100, 200, 300, 400])`, select elements at index `[1, 3]` with `arr[[1, 3]]`, and print.
[200 400]