code: def inbreeding_coefficient(g, fill=np.nan):
      
  
      # check inputs
      if not hasattr(g, 'count_het') or not hasattr(g, 'count_called'):
          g = GenotypeArray(g, copy=False)
  
      # calculate observed and expected heterozygosity
      ho = heterozygosity_observed(g)
      af = g.count_alleles().to_frequencies()
      he = heterozygosity_expected(af, ploidy=g.shape[-1], fill=0)
  
      # calculate inbreeding coefficient, accounting for variants with no
      # expected heterozygosity
      with ignore_invalid():
          f = np.where(he > 0, 1 - (ho / he), fill)
  
      return f
docs: Calculate the inbreeding coefficient 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 the expected heterozygosity is
          zero.
  
      Returns
      -------
  
      f : ndarray, float, shape (n_variants,)
          Inbreeding coefficient.
  
      Notes
      -----
  
      The inbreeding coefficient is calculated as *1 - (Ho/He)* where *Ho* is
      the observed heterozygosity and *He* is the expected 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.inbreeding_coefficient(g)
      array([        nan,  0.33333333,  1.        , -0.33333333])