parameters: (observed)
return_statement: return expected
docstring: Compute the expected frequencies from a contingency table.
  
      Given an n-dimensional contingency table of observed frequencies,
      compute the expected frequencies for the table based on the marginal
      sums under the assumption that the groups associated with each
      dimension are independent.
  
      Parameters
      ----------
      observed : array_like
          The table of observed frequencies.  (While this function can handle
          a 1-D array, that case is trivial.  Generally `observed` is at
          least 2-D.)
  
      Returns
      -------
      expected : ndarray of float64
          The expected frequencies, based on the marginal sums of the table.
          Same shape as `observed`.
  
      Examples
      --------
      >>> observed = np.array([[10, 10, 20],[20, 20, 20]])
      >>> from scipy.stats import expected_freq
      >>> expected_freq(observed)
      array([[ 12.,  12.,  16.],
             [ 18.,  18.,  24.]])
docstring_summary: Compute the expected frequencies from a contingency table.
docstring_tokens: Compute the expected frequencies from a contingency table .
function: def expected_freq(observed):
      """
      Compute the expected frequencies from a contingency table.
  
      Given an n-dimensional contingency table of observed frequencies,
      compute the expected frequencies for the table based on the marginal
      sums under the assumption that the groups associated with each
      dimension are independent.
  
      Parameters
      ----------
      observed : array_like
          The table of observed frequencies.  (While this function can handle
          a 1-D array, that case is trivial.  Generally `observed` is at
          least 2-D.)
  
      Returns
      -------
      expected : ndarray of float64
          The expected frequencies, based on the marginal sums of the table.
          Same shape as `observed`.
  
      Examples
      --------
      >>> observed = np.array([[10, 10, 20],[20, 20, 20]])
      >>> from scipy.stats import expected_freq
      >>> expected_freq(observed)
      array([[ 12.,  12.,  16.],
             [ 18.,  18.,  24.]])
  
      """
      # Typically `observed` is an integer array. If `observed` has a large
      # number of dimensions or holds large values, some of the following
      # computations may overflow, so we first switch to floating point.
      observed = np.asarray(observed, dtype=np.float64)
  
      # Create a list of the marginal sums.
      margsums = margins(observed)
  
      # Create the array of expected frequencies.  The shapes of the
      # marginal sums returned by apply_over_axes() are just what we
      # need for broadcasting in the following product.
      d = observed.ndim
      expected = reduce(np.multiply, margsums) / observed.sum() ** (d - 1)
      return expected
function_tokens: def expected_freq ( observed ) : # Typically `observed` is an integer array. If `observed` has a large # number of dimensions or holds large values, some of the following # computations may overflow, so we first switch to floating point. observed = np . asarray ( observed , dtype = np . float64 ) # Create a list of the marginal sums. margsums = margins ( observed ) # Create the array of expected frequencies.  The shapes of the # marginal sums returned by apply_over_axes() are just what we # need for broadcasting in the following product. d = observed . ndim expected = reduce ( np . multiply , margsums ) / observed . sum ( ) ** ( d - 1 ) return expected