def _expected(observed):
 o = observed
 if (len(o) == 0):
  return []
 if (len(o) == 1):
  return [([(sum(o[0]) / float(len(o[0])))] * len(o[0]))]
 n = [sum(o[i]) for i in xrange(len(o))]
 m = [sum((o[i][j] for i in xrange(len(o)))) for j in xrange(len(o[0]))]
 s = float(sum(n))
 return [[((n[i] * m[j]) / s) for j in xrange(len(o[i]))] for i in xrange(len(o))]

def _expected ( observed ) : o = observed if ( len ( o ) == 0 ) : return [ ] if ( len ( o ) == 1 ) : return [ ( [ ( sum ( o [ 0 ] ) / float ( len ( o [ 0 ] ) ) ) ] * len ( o [ 0 ] ) ) ] n = [ sum ( o [ i ] ) for i in xrange ( len ( o ) ) ] m = [ sum ( ( o [ i ] [ j ] for i in xrange ( len ( o ) ) ) ) for j in xrange ( len ( o [ 0 ] ) ) ] s = float ( sum ( n ) ) return [ [ ( ( n [ i ] * m [ j ] ) / s ) for j in xrange ( len ( o [ i ] ) ) ] for i in xrange ( len ( o ) ) ]
returns the table of expected frequencies from the given table of observed frequencies .