code: def heterozygosity_observed(g, fill=np.nan):
      
  
      # check inputs
      if not hasattr(g, 'count_het') or not hasattr(g, 'count_called'):
          g = GenotypeArray(g, copy=False)
  
      # count hets
      n_het = np.asarray(g.count_het(axis=1))
      n_called = np.asarray(g.count_called(axis=1))
  
      # calculate rate of observed heterozygosity, accounting for variants
      # where all calls are missing
      with ignore_invalid():
          ho = np.where(n_called > 0, n_het / n_called, fill)
  
      return ho
docs: Calculate the rate of observed heterozygosity for each variant.
  
      Parameters
      ----------
  
      g : array_like, int, shape (n_variants, n_samples, ploidy)
          Genotype array.
      fill : float, optional
          Use this value for variants where all calls are missing.
  
      Returns
      -------
  
      ho : ndarray, float, shape (n_variants,)
          Observed heterozygosity
  
      Examples
      --------
  
      >>> import allel
      >>> g = allel.GenotypeArray([[[0, 0], [0, 0], [0, 0]],
      ...                          [[0, 0], [0, 1], [1, 1]],
      ...                          [[0, 0], [1, 1], [2, 2]],
      ...                          [[1, 1], [1, 2], [-1, -1]]])
      >>> allel.heterozygosity_observed(g)
      array([0.        , 0.33333333, 0.        , 0.5       ])