Swap Two Rows

easynumpy_manipulation

Implement swap_rows(X, i, j).

Given a 2D array X and two row indices i, j, return a new array equal to X with rows i and j swapped (leave X unchanged). No for/while loops.

Constraints
  • no scipy, sklearn
  • no for/while loops

Your solution

Edit swap_rows and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

Fancy-index the two rows and assign them back in swapped order: out[[i, j]] = out[[j, i]].