code: def field_from_coo_matrix_and_data(x, data):
      """Instantiates a weighted graph from a (sparse) coo_matrix
  
      Parameters
      ----------
      x: (V, V) scipy.sparse.coo_matrix instance,
         the input matrix
      data: array of shape (V, dim),
            the field data
  
      Returns
      -------
      ifield: resulting Field instance
      """
      if x.shape[0] != x.shape[1]:
          raise ValueError("the input coo_matrix is not square")
      if data.shape[0] != x.shape[0]:
          raise ValueError("data and x do not have consistent shapes")
      i, j = x.nonzero()
      edges = np.vstack((i, j)).T
      weights = x.data
      ifield = Field(x.shape[0], edges, weights, data)
      return ifield
  
imports: from warnings import warn
  import numpy
  from .graph import Graph, WeightedGraph
label_desc: Use image node_id 1 for calling a global function with example usage: field_from_coo_matrix_and_data(x, data) and returns: ifield