code: def _reshape_2d_4d(M, mask, out=None):
      """
      Faster reshape from 2D to 4D.
      """
      if out is None:
          out = np.zeros((*mask.shape, M.shape[-1]), dtype=M.dtype)
      n = 0
      for i, j, k in np.ndindex(mask.shape):
          if mask[i, j, k]:
              out[i, j, k, :] = M[n, :]
              n += 1
      return out
  
imports: import logging
  import warnings
  import numpy
  from dipy.core.geometry import vec2vec_rotmat
  from dipy.core.gradients import gradient_table, unique_bvals_tolerance, get_bval_indices
  from dipy.core.onetime import auto_attr
  from dipy.core.sphere import Sphere
  from dipy.data import get_sphere
  from dipy.reconst.shm import lazy_index, normalize_data
  from dipy.reconst.odf import OdfModel, OdfFit
  from dipy.reconst.csdeconv import AxSymShResponse
  from dipy.segment.mask import bounding_box, crop
  from dipy.sims.voxel import single_tensor, all_tensor_evecs
label_desc: Use image node_id 7 for calling a global function with example usage: _reshape_2d_4d(M, mask, out) and returns: out