class_docstr: Implement the thermometer encoding defence approach.
  
  | Paper link: https://openreview.net/forum?id=S18Su--CW
  
  | Please keep in mind the limitations of defences. For more information on the limitations of this defence,
      see https://arxiv.org/abs/1802.00420 . For details on how to evaluate classifier security in general, see
      https://arxiv.org/abs/1902.06705
docstr: Apply thermometer encoding to one channel.
  
  :param x: Sample to encode with shape `(batch_size, width, height)`.
  :return: Encoded sample with shape `(batch_size, width, height, num_space)`.
docstr_tok: ["Apply","thermometer","encoding","to","one","channel",".",":","param","x",":","Sample","to","encode","with","shape","`","(","batch_size",",","width",",","height",")","`",".",":","return",":","Encoded","sample","with","shape","`","(","batch_size",",","width",",","height",",","num_space",")","`","."]
code: def _perchannel(self, x: np.ndarray) -> np.ndarray:
      """
      Apply thermometer encoding to one channel.
  
      :param x: Sample to encode with shape `(batch_size, width, height)`.
      :return: Encoded sample with shape `(batch_size, width, height, num_space)`.
      """
      pos = np.zeros(shape=x.shape)
      for i in range(1, self.num_space):
          pos[x > float(i) / self.num_space] += 1
  
      onehot_rep = to_categorical(pos.reshape(-1), self.num_space)
  
      for i in range(self.num_space - 1):
          onehot_rep[:, i] += np.sum(onehot_rep[:, i + 1 :], axis=1)
  
      return onehot_rep.flatten()
  
file_path: adversarial-robustness-toolbox/art/defences/preprocessor/thermometer_encoding.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Tuple, TYPE_CHECKING
  import numpy
  from art.config import ART_NUMPY_DTYPE
  from art.defences.preprocessor.preprocessor import Preprocessor
  from art.utils import to_categorical
label_desc: Use image node_id 3 for calling the ThermometerEncoding obj's underlying member method code with example usage: obj._perchannel(x) and returns: onehot_rep