Reshape to a Matrix
easynumpy_basicsImplement to_matrix(x, rows).
Given a 1D array x whose length is divisible by rows, reshape it into a
2D array with rows rows (row-major / C order). Let NumPy infer the number
of columns by passing -1 for that dimension. No for/while loops.
Constraints
- no for/while loops
Your solution
Edit to_matrix and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
Pass -1 for the unknown dimension: x.reshape(rows, -1) lets NumPy compute the columns.