code: def dw(self):
          r
          if self._dw is None:
              if not self.is_directed():
                  # Shortcut for undirected graphs.
                  self._dw = np.ravel(self.W.sum(axis=0))
              else:
                  degree_in = np.ravel(self.W.sum(axis=0))
                  degree_out = np.ravel(self.W.sum(axis=1))
                  self._dw = (degree_in + degree_out) / 2
          return self._dw
docs: r"""The weighted degree of vertices.
  
          For undirected graphs, the weighted degree of the vertex :math:`v_i` is
          defined as
  
          .. math:: d[i] = \sum_j W[j, i] = \sum_j W[i, j],
  
          where :math:`W` is the weighted adjacency matrix :attr:`W`.
  
          For directed graphs, the weighted degree of the vertex :math:`v_i` is
          defined as
  
          .. math:: d[i] = \frac12 (d^\text{in}[i] + d^\text{out}[i])
                         = \frac12 (\sum_j W[j, i] + \sum_j W[i, j]),
  
          i.e., as the average of the in and out degrees.
  
          Examples
          --------
  
          Undirected graph:
  
          >>> graph = graphs.Graph([
          ...     [0, 1, 0],
          ...     [1, 0, 2],
          ...     [0, 2, 0],
          ... ])
          >>> print(graph.d)  # Number of neighbors.
          [1 2 1]
          >>> print(graph.dw)  # Weighted degree.
          [1 3 2]
  
          Directed graph:
  
          >>> graph = graphs.Graph([
          ...     [0, 1, 0],
          ...     [0, 0, 2],
          ...     [0, 2, 0],
          ... ])
          >>> print(graph.d)  # Number of neighbors.
          [0.5 1.5 1. ]
          >>> print(graph.dw)  # Weighted degree.
          [0.5 2.5 2. ]