{"record":{"id":"4e86f6a8bc3e128b","repo":"roboflow/supervision","slug":"confusion-matrix-must-have-shape-3-got-co-4e86f6","errorCode":null,"errorMessage":"Confusion matrix must have shape (..., 3), got {confusion_matrix.shape}","messagePattern":"Confusion matrix must have shape \\(\\.\\.\\., 3\\), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/metrics/precision.py","lineNumber":496,"sourceCode":"        result_matrix: npt.NDArray[np.float64] = confusion_matrix\n        return result_matrix\n\n    @staticmethod\n    def _compute_precision(\n        confusion_matrix: npt.NDArray[np.float64],\n    ) -> npt.NDArray[np.float64]:\n        \"\"\"\n        Broadcastable function, computing the precision from the confusion matrix.\n\n        Args:\n            confusion_matrix: shape (N, ..., 3), where the last dimension\n                contains the true positives, false positives, and false negatives.\n\n        Returns:\n            shape (N, ...), containing the precision for each element.\n        \"\"\"\n        if not confusion_matrix.shape[-1] == 3:\n            raise ValueError(\n                f\"Confusion matrix must have shape (..., 3), got \"\n                f\"{confusion_matrix.shape}\"\n            )\n        true_positives = confusion_matrix[..., 0]\n        false_positives = confusion_matrix[..., 1]\n\n        denominator = true_positives + false_positives\n        precision = np.divide(\n            true_positives,\n            denominator,\n            out=np.zeros_like(true_positives),\n            where=denominator != 0,\n        )\n\n        result_precision: npt.NDArray[np.float64] = precision\n        return result_precision\n\n    def _detections_content(self, detections: Detections) -> npt.NDArray[Any]:","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/metrics/precision.py#L478-L514","documentation":"Error \"Confusion matrix must have shape (..., 3), got {confusion_matrix.shape}\" thrown in roboflow/supervision.","triggerScenarios":"Thrown at src/supervision/metrics/precision.py:496 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide a confusion matrix whose last dimension is 3.","Use the metric's own computation methods to build the matrix instead of constructing it manually."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}