docstr: Generates a binary mask of dimension [num_samples, M] where M is the number of
  image superpixels (segments).
  
  Parameters
  ----------
  num_samples
      Number of perturbed images to be generated
  p_sample:
      The probability that a superpixel is perturbed
  
  Returns
  -------
  data
      Binary 2D mask, where each non-zero entry in a row indicates that
      the values of the particular image segment will not be perturbed.
docstr_tok: ["Generates","a","binary","mask","of","dimension","[","num_samples",",","M","]","where","M","is","the","number","of","image","superpixels","(","segments",")",".","Parameters","--","--","--","--","--","num_samples","Number","of","perturbed","images","to","be","generated","p_sample",":","The","probability","that","a","superpixel","is","perturbed","Returns","--","--","--","-","data","Binary","2D","mask",",","where","each","non-zero","entry","in","a","row","indicates","that","the","values","of","the","particular","image","segment","will","not","be","perturbed","."]
code: def _choose_superpixels(
      self, num_samples: int, p_sample: float = 0.5
  ) -> np.ndarray:
      """
      Generates a binary mask of dimension [num_samples, M] where M is the number of
      image superpixels (segments).
  
      Parameters
      ----------
      num_samples
          Number of perturbed images to be generated
      p_sample:
          The probability that a superpixel is perturbed
  
      Returns
      -------
      data
          Binary 2D mask, where each non-zero entry in a row indicates that
          the values of the particular image segment will not be perturbed.
      """
  
      n_features = len(self.segment_labels)
      data = np.random.choice(
          [0, 1], num_samples * n_features, p=[p_sample, 1 - p_sample]
      )
      data = data.reshape((num_samples, n_features))
  
      return data
  
imports: import copy
  import logging
  from functools import partial
  from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
  import numpy
  from skimage.segmentation import felzenszwalb, quickshift, slic
  from alibi.api.defaults import DEFAULT_DATA_ANCHOR_IMG, DEFAULT_META_ANCHOR
  from alibi.api.interfaces import Explainer, Explanation
  from alibi.exceptions import PredictorCallError, PredictorReturnTypeError
  from alibi.utils.wrappers import ArgmaxTransformer
  from .anchor_base import AnchorBaseBeam
  from .anchor_explanation import AnchorExplanation
label_desc: Use image node_id 4 for calling the AnchorImageSampler obj's underlying member method code with example usage: obj._choose_superpixels(num_samples, p_sample) and returns: data