def _confusion_matrix(y_true, y_pred, num_classes):
        """
        Creates a confusion matrix as a numpy array using vectorized operations.

        Parameters:
        - y_true: array-like, true class labels.
        - y_pred: array-like, predicted class labels.
        - num_classes: int, number of classes.

        Returns:
        - conf_matrix: np.ndarray, confusion matrix of shape (num_classes,
                                                              num_classes).
        """
        # Map pairs of (y_true, y_pred) to indices in the confusion matrix
        indices = y_true * num_classes + y_pred
        # Count occurrences of each index
        conf_matrix = np.bincount(indices, minlength=num_classes * num_classes)
        # Reshape the flat array into a 2D confusion matrix
        conf_matrix = conf_matrix.reshape((num_classes, num_classes))
        return conf_matrix

        Creates a confusion matrix as a numpy array using vectorized operations.

        Parameters:
        - y_true: array-like, true class labels.
        - y_pred: array-like, predicted class labels.
        - num_classes: int, number of classes.

        Returns:
        - conf_matrix: np.ndarray, confusion matrix of shape (num_classes,
                                                              num_classes).
        
keras/src/metrics/iou_metrics_test.py