gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
Given a matrix, return its transpose.
- User
Given a matrix, return its transpose.
- Assistant
Certainly! To transpose a matrix means to swap its rows and columns. For a given matrix
matrix, the transpose is a new matrix where the element at position[i][j]in the original becomes[j][i]in the transpose.Here’s a simple Python function to return the transpose of a matrix:
pythondef transpose(matrix): """ Returns the transpose of the given matrix. Args: matrix (list of lists): The input matrix. Returns: list of lists: The transposed matrix. """ # Using list comprehension return [list(row) for row in zip(*matrix)] # Example usage: matrix = [ [1, 2, 3], [4, 5, 6] ] print(transpose(matrix)) # Output: [[1, 4], [2, 5], [3, 6]]
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.