code: def _matrices_to_structure_model(
      w_est: np.ndarray, a_est: np.ndarray
  ) -> StructureModel:
      """
      Converts the matrices output by dynotears (W and A) into a StructureModel
      We use the following convention:
      - {var}_lag{l} where l is the lag value (i.e. from how many previous timestamps the edge is coming
      - if we deal with a intra_slice_node, `l == 0`
      Args:
          w_est: Intra-slice weight matrix
          a_est: Inter-slice matrix
  
      Returns:
          StructureModel representing the structure learnt
  
      """
      sm = StructureModel()
      lag_cols = [
          f"{var}_lag{l_val}"
          for l_val in range(1 + (a_est.shape[0] // a_est.shape[1]))
          for var in range(a_est.shape[1])
      ]
      sm.add_nodes_from(lag_cols)
      sm.add_edges_from(
          [
              (lag_cols[i], lag_cols[j], {"weight": w_est[i, j]})
              for i in range(w_est.shape[0])
              for j in range(w_est.shape[1])
              if w_est[i, j] != 0
          ]
      )
      sm.add_edges_from(
          [
              (
                  lag_cols[i + w_est.shape[0]],
                  lag_cols[j],
                  {"weight": a_est[i, j]},
              )
              for i in range(a_est.shape[0])
              for j in range(a_est.shape[1])
              if a_est[i, j] != 0
          ]
      )
      return sm
  
file_path: causalnex/causalnex/structure/dynotears.py
imports: import warnings
  from typing import Dict, List, Tuple, Union
  import numpy
  import pandas
  import scipy.linalg
  import scipy.optimize
  from causalnex.structure import StructureModel
  from causalnex.structure.transformers import DynamicDataTransformer
label_desc: Use image node_id 4 for calling a global function with example usage: _matrices_to_structure_model(w_est, a_est) and returns: sm