class_docstr: These attacks were originally implemented by Vargas et al. (2019) & Su et al.(2019).
  
  | One Pixel Attack Paper link: https://arxiv.org/abs/1710.08864
  | Pixel and Threshold Attack Paper link: https://arxiv.org/abs/1906.06026
docstr: Generate adversarial samples and return them in an array.
  
  :param x: An array with the original inputs.
  :param y: Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or indices of shape
            (nb_samples,). Only provide this parameter if you'd like to use true labels when crafting adversarial
            samples. Otherwise, model predictions are used as labels to avoid the "label leaking" effect
            (explained in this paper: https://arxiv.org/abs/1611.01236). Default is `None`.
  :param max_iter: Maximum number of optimisation iterations.
  :return: An array holding the adversarial examples.
docstr_tok: ["Generate","adversarial","samples","and","return","them","in","an","array",".",":","param","x",":","An","array","with","the","original","inputs",".",":","param","y",":","Target","values","(","class","labels",")","one-hot-encoded","of","shape","(","nb_samples",",","nb_classes",")","or","indices","of","shape","(","nb_samples",",",")",".","Only","provide","this","parameter","if","you","'d","like","to","use","true","labels","when","crafting","adversarial","samples",".","Otherwise",",","model","predictions","are","used","as","labels","to","avoid","the","``","label","leaking","''","effect","(","explained","in","this","paper",":","https",":","\/\/arxiv.org\/abs\/1611.01236",")",".","Default","is","`","None","`",".",":","param","max_iter",":","Maximum","number","of","optimisation","iterations",".",":","return",":","An","array","holding","the","adversarial","examples","."]
code: def generate(
      self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs
  ) -> np.ndarray:
      """
      Generate adversarial samples and return them in an array.
  
      :param x: An array with the original inputs.
      :param y: Target values (class labels) one-hot-encoded of shape (nb_samples, nb_classes) or indices of shape
                (nb_samples,). Only provide this parameter if you'd like to use true labels when crafting adversarial
                samples. Otherwise, model predictions are used as labels to avoid the "label leaking" effect
                (explained in this paper: https://arxiv.org/abs/1611.01236). Default is `None`.
      :param max_iter: Maximum number of optimisation iterations.
      :return: An array holding the adversarial examples.
      """
      if y is not None:
          y = check_and_transform_label_format(
              y,
              nb_classes=self.estimator.nb_classes,
              return_one_hot=False,
          )
  
      if y is None:
          if self.targeted:
              raise ValueError(
                  "Target labels `y` need to be provided for a targeted attack."
              )
          y = np.argmax(self.estimator.predict(x), axis=1)
      else:
          if self.estimator.nb_classes == 2 and y.shape[1] == 1:
              raise ValueError(
                  "This attack has not yet been tested for binary classification with a single output classifier."
              )
          if y.ndim > 1 and y.shape[1] > 1:
              y = np.argmax(y, axis=1)
  
      y = y.flatten()  # type: ignore
  
      if self.th is None:
          logger.info(
              "Performing minimal perturbation Attack. \
                  This could take long time to process. \
                  For sanity check, pass th=10 to the Attack instance."
          )
  
      # NOTE: Pixel and Threshold Attacks are well defined for unprocessed images where the pixel values are,
      #       8-Bit color i.e., the pixel values are np.uint8 in range [0, 255].
  
      # TO-DO: Better checking of input image.
      #        All other cases not tested needs the images to be rescaled to [0, 255].
      if self.estimator.clip_values[1] != 255.0:
          self.rescale = True
          x = (x - self.estimator.clip_values[0]) / (
              self.estimator.clip_values[1]
              - self.estimator.clip_values[0]
          )
          x = x * 255.0
  
      x = x.astype(ART_NUMPY_DTYPE)
  
      adv_x_best = []
      self.adv_th = []
      for image, target_class in tqdm(zip(x, y), desc="Pixel threshold", disable=not self.verbose):  # type: ignore
          if self.th is None:
              min_th = -1
              start, end = 1, 127
  
              image_result = image
  
              while True:  # pragma: no cover
                  threshold = (start + end) // 2
                  success, trial_image_result = self._attack(
                      image, target_class, threshold
                  )
  
                  if success:
                      image_result = trial_image_result
                      end = threshold - 1
                      min_th = threshold
                  else:
                      start = threshold + 1
  
                  if end < start:
                      break
  
              self.adv_th = [min_th]
  
          else:
              success, image_result = self._attack(
                  image, target_class, self.th
              )
  
              if not success:
                  image_result = image
  
          adv_x_best += [image_result]
  
      adv_x_best_array = np.array(adv_x_best)
  
      if self.rescale:
          adv_x_best_array = self.rescale_input(adv_x_best_array)
  
      return adv_x_best_array
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from itertools import product
  from typing import List, Optional, Tuple, TYPE_CHECKING
  import numpy
  from six import string_types
  import scipy
  from scipy._lib._util import check_random_state
  from scipy.optimize import OptimizeResult, minimize
  from tqdm.auto import tqdm
  from art.config import ART_NUMPY_DTYPE
  from art.attacks.attack import EvasionAttack
  from art.estimators.estimator import BaseEstimator, NeuralNetworkMixin
  from art.estimators.classification.classifier import ClassifierMixin
  from art.utils import check_and_transform_label_format
label_desc: Use image node_id 4 for calling the PixelThreshold obj's underlying member method code with example usage: obj.generate(x, y) and returns: adv_x_best_array