code: def tomatrix(self):
      links = {}
  
      for node in self.graph:
          links[node] = len(links)
  
      rows, cols = [], []
  
      for from_node, to_nodes in self.graph.items():
          from_node_id = links[from_node]
  
          for to_node in to_nodes:
              to_node_id = links[to_node]
  
              rows.append(from_node_id)
              cols.append(to_node_id)
  
      n_links = len(self)
      data = np.ones(len(rows))
      matrix = sp.coo_matrix(
          (data, (rows, cols)), shape=(n_links, n_links)
      )
  
      return matrix
  
imports: import pprint
  from collections import OrderedDict, namedtuple
  import six
  import numpy
  import scipy.sparse
  from six.moves.urllib.parse import urlparse
  from pagerank import pagerank
label_desc: Use image node_id 8 for calling the WebPageGraph obj's underlying member method code with example usage: obj.tomatrix() and returns: matrix