code: def _apply_cluster_size_threshold(arr, cluster_threshold, copy=True):
      """Apply cluster-extent thresholding to voxel-wise thresholded array.
  
      Parameters
      ----------
      arr : :obj:`numpy.ndarray` of shape (X, Y, Z)
          3D array that has been thresholded at the voxel level.
      cluster_threshold : :obj:`float`
          Cluster-size threshold, in voxels, to apply to ``arr``.
      copy : :obj:`bool`, default=True
          Whether to copy the array before modifying it or not.
  
      Returns
      -------
      arr : :obj:`numpy.ndarray` of shape (X, Y, Z)
          Cluster-extent thresholded array.
  
      Notes
      -----
      Clusters are defined in a bi-sided manner;
      both negative and positive clusters are evaluated,
      but this is done separately for each sign.
  
      Clusters are defined using 6-connectivity, also known as NN1 (in AFNI) or
      "faces" connectivity.
      """
      assert arr.ndim == 3
  
      if copy:
          arr = arr.copy()
  
      # Define array for 6-connectivity, aka NN1 or "faces"
      bin_struct = generate_binary_structure(3, 1)
  
      for sign in np.unique(np.sign(arr)):
          # Binarize using one-sided cluster-defining threshold
          binarized = ((arr * sign) > 0).astype(int)
  
          # Apply cluster threshold
          label_map = label(binarized, bin_struct)[0]
          clust_ids = sorted(list(np.unique(label_map)[1:]))
          for c_val in clust_ids:
              if np.sum(label_map == c_val) < cluster_threshold:
                  arr[label_map == c_val] = 0
  
      return arr
  
imports: import collections.abc
  import copy
  import itertools
  import warnings
  import nibabel
  import numpy
  from joblib import Memory, Parallel, delayed
  from scipy.ndimage import gaussian_filter1d, generate_binary_structure, label
  from scipy.stats import scoreatpercentile
  from ..None import signal
  from .._utils import _repr_niimgs, as_ndarray, check_niimg, check_niimg_3d, check_niimg_4d, fill_doc
  from .._utils.exceptions import DimensionError
  from .._utils.helpers import rename_parameters, stringify_path
  from .._utils.niimg import _get_data, safe_get_data
  from .._utils.niimg_conversions import _index_img, check_same_fov, iter_check_niimg
  from .._utils.param_validation import check_threshold
  from .._utils.path_finding import resolve_globbing
label_desc: Use image node_id 16 for calling a global function with example usage: _apply_cluster_size_threshold(arr, cluster_threshold, copy) and returns: arr