import six


def intersect(*masks):
  """Return new masks that are the per-layer intersection of the provided masks.

  Args:
    *masks: The set of masks to intersect.
  Returns:
    The intersection of the provided masks.
  """
  result = {}
  for mask in masks:
    for layer, values in six.iteritems(mask):
      if layer in result:
        result[layer] *= values
      else:
        result[layer] = values
  return result