input: Write a function to optimize a Python program that processes a 2D array and stores the transpose output in a new array. The function should efficiently transpose the given array and return the transposed matrix.
  assert transpose([[1, 2, 3], [4, 5, 6]])==[[1, 4], [2, 5], [3, 6]]
  assert transpose([[1, 2], [3, 4], [5, 6]])==[[1, 3, 5], [2, 4, 6]]
  assert transpose([[7, 8], [9, 10], [11, 12]])==[[7, 9, 11], [8, 10, 12]]
  assert transpose([[1], [2], [3]])==[[1, 2, 3]]
  assert transpose([[1, 2, 3]])==[[1], [2], [3]]
output: def transpose(matrix):
      return [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]