def _perturb_image(self, x: np.ndarray, img: np.ndarray) -> np.ndarray:
        """
        Perturbs the given image `img` with the given perturbation `x`.
        """
        if x.ndim < 2:
            x = x[None, ...]
        imgs = np.tile(img, [len(x)] + [1] * (x.ndim + 1))
        x = x.astype(int)
        for adv, image in zip(x, imgs):
            for count, (i, j, k) in enumerate(
                product(
                    range(image.shape[-3]),
                    range(image.shape[-2]),
                    range(image.shape[-1]),
                )
            ):
                image[i, j, k] = adv[count]
        return imgs

        Perturbs the given image `img` with the given perturbation `x`.
        
art/attacks/evasion/pixel_threshold.py