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 take a 2d array A as input and return a 2d array B which is the transpose of A. If the input array is empty, the function should return an empty array.
  
  def transpose(A):
      if not A or not A[0]:
          return []
      n = len(A)
      m = len(A[0])
      B = [[A[j][i] for j in range(n)] for i in range(m)]
      return B
  
  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([[1]]) == [[1]]
  assert transpose([]) == []
  assert transpose([[]]) == []
output: def transpose(A):
      if not A or not A[0]:
          return []
      n = len(A)
      m = len(A[0])
      B = [[A[j][i] for j in range(n)] for i in range(m)]
      return B