Write a function reshape_array(arr, rows, cols) that reshapes a 1D numpy array into a 2D array with the given dimensions. You may use np.reshape().
Example:
Input: arr = [1, 2, 3, 4, 5, 6], rows = 2, cols = 3
Output: [[1, 2, 3],
[4, 5, 6]]
Constraints:
Test Cases
Test Case 1
Input:
[1, 2, 3, 4, 5, 6], 2, 3Expected:
[[1, 2, 3], [4, 5, 6]]Test Case 2
Input:
[1, 2, 3, 4], 2, 2Expected:
[[1, 2], [3, 4]]Test Case 3
Input:
[1, 2, 3, 4, 5, 6], 3, 2Expected:
[[1, 2], [3, 4], [5, 6]]+ 2 hidden test cases