code: def _extract_3d_patches(arr, patch_radius):
      """Extract 3D patches from 4D DWI data.
  
      Parameters
      ----------
      arr : ndarray
          The 4D noisy DWI data to be denoised.
  
      patch_radius : int or 1D array
          The radius of the local patch to be taken around each voxel (in
          voxels).
  
      Returns
      -------
      all_patches : ndarray
          All 3D patches flattened out to be 2D corresponding to the each 3D
          volume of the 4D DWI data.
  
      """
      if isinstance(patch_radius, int):
          patch_radius = np.ones(3, dtype=int) * patch_radius
      if len(patch_radius) != 3:
          raise ValueError("patch_radius should have length 3")
      else:
          patch_radius = np.asarray(patch_radius, dtype=int)
      patch_size = 2 * patch_radius + 1
  
      dim = arr.shape[-1]
  
      all_patches = []
  
      # loop around and find the 3D patch for each direction
      for i in range(
          patch_radius[0], arr.shape[0] - patch_radius[0], 1
      ):
          for j in range(
              patch_radius[1], arr.shape[1] - patch_radius[1], 1
          ):
              for k in range(
                  patch_radius[2], arr.shape[2] - patch_radius[2], 1
              ):
                  ix1 = i - patch_radius[0]
                  ix2 = i + patch_radius[0] + 1
                  jx1 = j - patch_radius[1]
                  jx2 = j + patch_radius[1] + 1
                  kx1 = k - patch_radius[2]
                  kx2 = k + patch_radius[2] + 1
  
                  X = arr[ix1:ix2, jx1:jx2, kx1:kx2].reshape(
                      np.prod(patch_size), dim
                  )
                  all_patches.append(X)
  
      return np.array(all_patches).T
  
file_path: dipy/dipy/denoise/patch2self.py
imports: import numpy
  from warnings import warn
  import time
  from dipy.utils.optpkg import optional_package
  import dipy.core.optimize
label_desc: Use image node_id 3 for calling a global function with example usage: _extract_3d_patches(arr, patch_radius) and returns: np