📘
Array Reshaping
EasyNumPy Reshaping
Problem Statement
Reshape arrays into different dimensions.
Background
NumPy reshape operations:
- arr.reshape(m, n) - reshape to m×n
- arr.reshape(-1) - flatten
- arr.reshape(-1, 1) - column vector
- arr.T or arr.transpose() - transpose
Your Task
Write a function reshape_array(arr, rows, cols) that reshapes a 1D array.
Output Format
Return a dictionary with:
- "reshaped": Array reshaped to (rows, cols) as list
- "transposed": Transposed (cols, rows) as list
- "flattened": Flattened back to 1D as list
- "column_vec": As column vector (n, 1) as list
Example:
Input:
arr = [1,2,3,4,5,6], rows = 2, cols = 3
Output:
{'reshaped': [[1, 2, 3], [4, 5, 6]], ...}Reasoning:
reshape(2,3) creates 2 rows of 3, transpose swaps dimensions
Constraints:
- Array size must equal rows * cols
- Use -1 for automatic dimension calculation
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.