PY-65

Build and Check a Labelled Count Table

  • Medium
  • Array Summaries
  • Python

Task

Write build_count_table(expected, produced, labels). The two outcome sequences must have equal length. labels must be non-empty and unique, and every outcome must appear in it. Raise ValueError with "unequal lengths", "empty labels", "duplicate label: <label>", or "unknown label: <label>", checking in that order and scanning expected before produced for unknown labels.

On success return a dictionary with labels as a tuple, a square integer NumPy counts array whose rows are expected and columns produced, row_totals, column_totals, and integer total. All totals must be derived from counts.

Example

Expected ['cat','cat','dog'], produced ['cat','dog','dog'], and labels ['cat','dog'] produce counts [[1,1],[0,1]], row totals [2,1], column totals [1,2], and total 3.

Your implementation

You may import NumPy as np. Do not modify inputs, print, or ask for input.