Optimize the following code in Python by improving its complexity.
def my_function(input_array):
  output_array = []
  for elem in input_array:
    if elem not in output_array:
      output_array.append(elem)
  return output_array
def my_function(input_array):
  output_array = set()
  return output_array.union(input_array)