PIXELBANKv9.1.0
Menu

Problem Statement

Transpose a 2D NumPy array (swap rows and columns).

Background

Transposing swaps rows and columns of a matrix. For an array of shape (m, n), transpose gives shape (n, m).

Your Task

Write a function transpose_array(arr) that:

  1. Transposes the input 2D array
  2. Returns a dictionary with:
    • "original_shape": Original shape as list
    • "transposed_shape": New shape as list
    • "array": Transposed array as nested list

Output Format

Return a dictionary with exactly these three keys.

Example:

Input:
[[1, 2, 3], [4, 5, 6]]
Output:
{'original_shape': [2, 3], 'transposed_shape': [3, 2], 'array': [[1, 4], [2, 5], [3, 6]]}
Reasoning:

2×32 \times 3 matrix becomes 3x2 after transpose

Constraints:

  • Use .T attribute or np.transpose()
  • Input will always be 2D
  • Return shapes as lists
solution.py

Test Results

0/0
Run code to see test results.
Transpose Array - Easy | PixelBank