code: def grad_tensor(grad, evals):
      """
      Calculate the 3 by 3 tensor for a given spatial gradient, given a canonical
      tensor shape (also as a 3 by 3), pointing at [1,0,0]
  
      Parameters
      ----------
      grad : 1d array of shape (3,)
          The spatial gradient (e.g between two nodes of a streamline).
  
      evals: 1d array of shape (3,)
          The eigenvalues of a canonical tensor to be used as a response
          function.
  
      """
      # This is the rotation matrix from [1, 0, 0] to this gradient of the sl:
      R = la.svd([grad], overwrite_a=True)[2]
      # This is the 3 by 3 tensor after rotation:
      T = np.linalg.multi_dot([R, np.diag(evals), R.T])
      return T
  
imports: import numpy
  import scipy.sparse
  import scipy.linalg
  from dipy.reconst.base import ReconstModel, ReconstFit
  from dipy.tracking.utils import unique_rows
  from dipy.tracking.streamline import transform_streamlines
  from dipy.tracking.vox2track import _voxel2streamline
  import dipy.data
  import dipy.core.optimize
label_desc: Use image node_id 3 for calling a global function with example usage: grad_tensor(grad, evals) and returns: T