code: def _field_gradient_jac(ref, target):
      """
      Given a reference field ref and a target field target
      compute the jacobian of the target with respect to ref
  
      Parameters
      ----------
      ref: Field instance
          that yields the topology of the space
      target : array of shape(ref.V,dim)
  
      Returns
      -------
      fgj: array of shape (ref.V)
          that gives the jacobian implied by the ref.field->target transformation.
      """
      import numpy.linalg as nl
  
      n = ref.V
      xyz = ref.field
      dim = xyz.shape[1]
      fgj = []
      ln = ref.list_of_neighbors()
      for i in range(n):
          j = ln[i]
          if np.size(j) > dim - 1:
              dx = np.squeeze(xyz[j] - xyz[i])
              df = np.squeeze(target[j] - target[i])
              FG = np.dot(nl.pinv(dx), df)
              fgj.append(nl.det(FG))
          else:
              fgj.append(1)
  
      fgj = np.array(fgj)
      return fgj
  
file_path: nipy/nipy/labs/spatial_models/hierarchical_parcellation.py
imports: from warnings import warn
  import numpy
  from numpy.random import rand
  from nipy.algorithms.clustering.utils import kmeans, voronoi
  from nipy.algorithms.graph.field import Field
  from nipy.algorithms.graph.graph import wgraph_from_coo_matrix
  from .parcellation import MultiSubjectParcellation
label_desc: Use image node_id 3 for calling a global function with example usage: _field_gradient_jac(ref, target) and returns: fgj