Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-071

Expected Counts Table

Problem

Return the table of expected counts for a 2D table of observed counts, where e_ij = row_total_i * col_total_j / total. Return [] for an empty table and a table of zeros when the total is zero.

Hint

Compute the row totals and column totals once, then divide their products by the grand total.

Test cases

case 1
in: [[[10,20],[30,40]]]
expected: [[12,18],[28,42]]
case 2
in: [[[1,2,3],[3,2,1]]]
expected: [[2,2,2],[2,2,2]]
case 3
in: [[[10,0],[0,10]]]
expected: [[5,5],[5,5]]
case 4
in: [[[0,0],[0,0]]]
expected: [[0,0],[0,0]]
case 5
in: [[[20,30,50]]]
expected: [[20,30,50]]
Starter codePython
def expected_counts(observed):
    # Your code here
    pass

5 test cases · run your code against them in the editor