Matrix Transpose
Matrix Transpose
Implement the transpose of a matrix, where each element at position (i, j) is swapped to (j, i).
Mathematical Definition
Transpose Operation:
(AT)ji=AijAn n×m matrix becomes an m×n matrix.
Function Arguments
A: 2D NumPy array, shape (N, M)- input matrix
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
.Tornp.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
Log in to take notes on this problem
Accepts: array
Matrix Transpose
Matrix Transpose
Implement the transpose of a matrix, where each element at position (i, j) is swapped to (j, i).
Mathematical Definition
Transpose Operation:
(AT)ji=AijAn n×m matrix becomes an m×n matrix.
Function Arguments
A: 2D NumPy array, shape (N, M)- input matrix
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
.Tornp.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
Log in to take notes on this problem
Accepts: array