Source code for mlprodict.onnxrt.ops_cpu.op_binarizer

# -*- encoding: utf-8 -*-
# pylint: disable=E0203,E1101,C0111
"""
Runtime operator.


:githublink:`%|py|7`
"""
import numpy
from ._op import OpRunUnaryNum


[docs]class Binarizer(OpRunUnaryNum): atts = {'threshold': 0.}
[docs] def __init__(self, onnx_node, desc=None, **options): OpRunUnaryNum.__init__(self, onnx_node, desc=desc, expected_attributes=Binarizer.atts, **options)
[docs] def _run(self, x): # pylint: disable=W0221 X = x.copy() cond = X > self.threshold not_cond = numpy.logical_not(cond) X[cond] = 1 X[not_cond] = 0 return (X, )