TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
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} (AT)ji​=Aij​

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

Function Arguments

  • A is a two-dimensional Python list of shape (N, M) representing the 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 an output array whose row and column counts are reversed.

Hint 2

Inside nested loops, assign output[j, i] from A[i][j].

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
Matrix TraceMatrix InverseMake DiagonalDot ProductMatrix Normalization

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

You must run your code first.
PrevNext

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} (AT)ji​=Aij​

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

Function Arguments

  • A is a two-dimensional Python list of shape (N, M) representing the 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 an output array whose row and column counts are reversed.

Hint 2

Inside nested loops, assign output[j, i] from A[i][j].

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
Matrix TraceMatrix InverseMake DiagonalDot ProductMatrix Normalization

Sign in to take notes on this problem

Case 1
Case 2
Case 3

Accepts: array

You must run your code first.