code: def mean(l, ignore_nan=False, empty=0):
      
      l = iter(l)
      if ignore_nan:
          l = ifilterfalse(np.isnan, l)
      try:
          n = 1
          acc = next(l)
      except StopIteration:
          if empty == 'raise':
              raise ValueError('Empty mean')
          return empty
      for n, v in enumerate(l, 2):
          acc += v
      if n == 1:
          return acc
      return acc / n
docs: nanmean compatible with generators.