Problems
Loading...
1 / 1

Matrix Transpose

Linear Algebra
Easy

Implement the transpose of a matrix, where each element at position (i, j) is swapped to (j, i).

Mathematical Definition

Transpose Operation:

(AT)ji=Aij(A^{T})_{ji} = A_{ij}

An n×m matrix becomes an m×n matrix.

Function Arguments

  • A: 2D NumPy array, shape (N, M) - input matrix
Loading visualization...

Examples

Input: A = [[1, 2, 3], [4, 5, 6]]

Output: [[1, 4], [2, 5], [3, 6]]

Input: A = [[1, 2], [3, 4]]

Output: [[1, 3], [2, 4]]

Input: A = [[1, 2, 3, 4]]

Output: [[1], [2], [3], [4]]

Hint 1

Create a new array with shape (m, n) using np.zeros(), then fill it with a nested loop.

Requirements

  • Return a new NumPy array of shape (M, N)
  • Must not modify the original matrix
  • Must work for non-square, rectangular matrices
  • Do not use .T or np.transpose()
  • Use manual indexing with loops or array operations

Constraints

  • 1 ≤ N, M ≤ 1000
  • Matrix elements can be any float or int
  • Time limit: 200ms
Try Similar Problems