class_docstr: Basic weighted, directed graph class
  
  Member variables:
  
  * V (int): the number of vertices
  * E (int): the number of edges
  
  Methods
  
  * vertices (list, type=int, shape=(V,)): vertices id
  * edges (list, type=int, shape=(E,2)): edges as vertices id tuples
  * weights (list, type=int, shape=(E,)): weights / lengths
    of the graph's edges
class_docstr_tok: ["Basic","weighted",",","directed","graph","class","Member","variables",":","*","V","(","int",")",":","the","number","of","vertices","*","E","(","int",")",":","the","number","of","edges","Methods","*","vertices","(","list",",","type=int",",","shape=","(","V",",",")",")",":","vertices","id","*","edges","(","list",",","type=int",",","shape=","(","E,2",")",")",":","edges","as","vertices","id","tuples","*","weights","(","list",",","type=int",",","shape=","(","E",",",")",")",":","weights","\/","lengths","of","the","graph","'s","edges"]
docstr: Creates a subgraph with the vertices for which valid>0
  and with the corresponding set of edges
  
  Parameters
  ----------
  valid, array of shape (self.V): nonzero for vertices to be retained
  
  Returns
  -------
  G, WeightedGraph instance, the desired subgraph of self
  
  Notes
  -----
  The vertices are renumbered as [1..p] where p = sum(valid>0) when
  sum(valid==0) then None is returned
docstr_tok: ["Creates","a","subgraph","with","the","vertices","for","which","valid",">","0","and","with","the","corresponding","set","of","edges","Parameters","--","--","--","--","--","valid",",","array","of","shape","(","self.V",")",":","nonzero","for","vertices","to","be","retained","Returns","--","--","--","-","G",",","WeightedGraph","instance",",","the","desired","subgraph","of","self","Notes","--","--","-","The","vertices","are","renumbered","as","[","1","..","p","]","where","p","=","sum","(","valid",">","0",")","when","sum","(","valid==0",")","then","None","is","returned"]
code: def subgraph(self, valid):
      """Creates a subgraph with the vertices for which valid>0
      and with the corresponding set of edges
  
      Parameters
      ----------
      valid, array of shape (self.V): nonzero for vertices to be retained
  
      Returns
      -------
      G, WeightedGraph instance, the desired subgraph of self
  
      Notes
      -----
      The vertices are renumbered as [1..p] where p = sum(valid>0) when
      sum(valid==0) then None is returned
      """
      if np.size(valid) != self.V:
          raise ValueError("incompatible size for self anf valid")
  
      if np.sum(valid > 0) == 0:
          return None
  
      if self.E > 0:
          win_edges = (valid[self.edges]).min(1) > 0
          edges = self.edges[win_edges]
          weights = self.weights[win_edges]
          renumb = np.hstack((0, np.cumsum(valid > 0)))
          edges = renumb[edges]
          G = WeightedGraph(np.sum(valid > 0), edges, weights)
      else:
          G = WeightedGraph(np.sum(valid > 0))
  
      return G
  
imports: import numpy
  from scipy.sparse import coo_matrix
label_desc: Use image node_id 17 for calling the WeightedGraph obj's underlying member method code with example usage: obj.subgraph(valid) and returns: G, None