#NEWLINE# def _expected( observed ) : #NEWLINE# #INDENT# ' Returns the table of (absolute) expected frequencies\n        from the given table of observed frequencies.\n    ' #NEWLINE# o = observed #NEWLINE# if ( len ( o ) == 0 ) : #NEWLINE# #INDENT# return [ ] #NEWLINE# #UNINDENT# if ( len ( o ) == 1 ) : #NEWLINE# #INDENT# return [ ( [ ( sum ( i [ 0 ] ) / float ( len ( o [ 0 ] ) ) ) ] * len ( o [ 0 ] ) ) ] #NEWLINE# #UNINDENT# n = [ sum ( o [ i ] ) for i in xrange ( len ( o ) ) ] #NEWLINE# m = [ sum ( ( o [ i ] [ j ] for i in xrange ( len ( o ) ) ) ) for j in xrange ( len ( o [ 0 ] ) ) ] #NEWLINE# s = float ( sum ( n ) ) #NEWLINE# return [ [ ( ( n [ i ] * m [ j ] ) / s ) for j in xrange ( len ( o [ i ] ) ) ] for i in xrange ( len ( o ) ) ]