input: Write a function to optimize the process of transposing a 2d array in Python and storing the result in a new array. The function should take a 2d array A as input and return the transposed array B.
  
  def transpose(A):
   n = len(A)
   m = len(A[0])
  
   B = [[0 for x in range(n)] for x in range(m)]
  
   for i in range(n):
   for j in range(m):
   B[j][i] = A[i][j]
  
   return B
  
  assert transpose([[1, 2, 3], [4, 5, 6]]) == [[1, 4], [2, 5], [3, 6]]
  assert transpose([[7, 8], [9, 10], [11, 12]]) == [[7, 9, 11], [8, 10, 12]]
  assert transpose([[1]]) == [[1]]
  assert transpose([[]]) == [[]]
  assert transpose([]) == []
output: def transpose(A):
      if not A:
          return []
      n = len(A)
      m = len(A[0])
      B = [[0 for _ in range(n)] for _ in range(m)]
      for i in range(n):
          for j in range(m):
              B[j][i] = A[i][j]
      return B