Statistical Methods
Audit Duplicate Coordinates in a Sparse Array
Define the task
Coordinate-format sparse data describe entries using row index, column index and value. Repeated coordinates may represent intended additive contributions or accidental duplicate records. Decide which interpretation applies before assembly. The teaching tool sums contributions at identical coordinates and displays a small dense reconstruction for inspection. It does not decide whether repeated source records should have been deduplicated instead. Use synthetic entries and keep the original source identifiers separately.
Carry out the check
Declare the matrix dimensions and zero-based indexing, then validate every coordinate against those dimensions. Group equal coordinate pairs and add their values. Distinguish the number of input records, unique occupied coordinates and nonzero assembled entries. Contributions can cancel, leaving an explicit zero; a stored zero and an absent entry may have different storage histories even when their numerical values agree. Current SciPy documentation provides a sparse-array interface; do not assume older matrix multiplication conventions transfer unchanged to arrays.
Worked hypothetical example
For a hypothetical 2×2 array with triplets (0,1,2),(0,1,3),(1,0,−1),(1,0,1), there are four records, two unique coordinates and one nonzero assembled entry. The reconstructed rows are (0,5) and (0,0). This example tests addition and cancellation, not permission to combine genuine duplicate participants. Record the aggregation rule with the data dictionary and retain an audit trail to the original contributions. Index errors should stop the process rather than silently enlarge the matrix.
Method checked 21 November 2026 against Primary method documentation: coo_array.