class_docstr: A class representing a set of binary confusion matrices at thresholds.
  
  For each threshold, in addition to the count of examples per prediction and
  label, this class also contains a sample of raw examples. Threshold values are
  sorted, and the entries within  tp[i], tn[i], fp[i], and fn[i] correspond to
  thresholds[i].
class_docstr_tok: ["A","class","representing","a","set","of","binary","confusion","matrices","at","thresholds",".","For","each","threshold",",","in","addition","to","the","count","of","examples","per","prediction","and","label",",","this","class","also","contains","a","sample","of","raw","examples",".","Threshold","values","are","sorted",",","and","the","entries","within","tp","[","i","]",",","tn","[","i","]",",","fp","[","i","]",",","and","fn","[","i","]","correspond","to","thresholds","[","i","]","."]
docstr: Applies an operator elementwise on self and `other` matrices.
docstr_tok: ["Applies","an","operator","elementwise","on","self","and","`","other","`","matrices","."]
code: def _apply_binary_op_elementwise(
      self, other: "Matrices", op: Callable[[float, float], float]
  ):
      """Applies an operator elementwise on self and `other` matrices."""
      tp, tn, fp, fn = [], [], [], []
      self_idx, other_idx = 0, 0
      merged_thresholds = []
      while True:
          if (
              self_idx < len(self.thresholds)
              and other_idx < len(other.thresholds)
              and self.thresholds[self_idx]
              == other.thresholds[other_idx]
          ):
              # threshold present in both, advance both indices
              merged_thresholds.append(self.thresholds[self_idx])
              tp.append(op(self.tp[self_idx], other.tp[other_idx]))
              tn.append(op(self.tn[self_idx], other.tn[other_idx]))
              fp.append(op(self.fp[self_idx], other.fp[other_idx]))
              fn.append(op(self.fn[self_idx], other.fn[other_idx]))
              self_idx += 1
              other_idx += 1
          elif self_idx < len(self.thresholds) and (
              other_idx >= len(other.thresholds)
              or self.thresholds[self_idx] < other.thresholds[other_idx]
          ):
              # threshold present in self but missing from other, use default values
              # for other and advance self_idx
              merged_thresholds.append(self.thresholds[self_idx])
              tp.append(op(self.tp[self_idx], 0))
              tn.append(op(self.tn[self_idx], 0))
              fp.append(op(self.fp[self_idx], 0))
              fn.append(op(self.fn[self_idx], 0))
              self_idx += 1
          elif other_idx < len(other.thresholds) and (
              self_idx >= len(self.thresholds)
              or other.thresholds[self_idx] < self.thresholds[other_idx]
          ):
              # threshold present in other but missing from self, use default values
              # for self and advance other_idx
              merged_thresholds.append(other.thresholds[other_idx])
              tp.append(op(0, other.tp[other_idx]))
              tn.append(op(0, other.tn[other_idx]))
              fp.append(op(0, other.fp[other_idx]))
              fn.append(op(0, other.fn[other_idx]))
              other_idx += 1
          else:
              assert self_idx >= len(
                  self.thresholds
              ) and other_idx >= len(other.thresholds)
              break
      return Matrices(
          thresholds=merged_thresholds, tp=tp, tn=tn, fp=fp, fn=fn
      )
  
imports: from typing import Any, Callable, Dict, Iterable, List, NamedTuple, Optional, Tuple, Union
  import apache_beam
  import numpy
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.contrib.aggregates import binary_confusion_matrices
  from tensorflow_model_analysis.metrics import calibration_histogram
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
label_desc: Use image node_id 1 for calling the Matrices obj's underlying member method code with example usage: obj._apply_binary_op_elementwise(other, op) and returns: Matrices