@not_implemented_for('undirected')
def stochastic_graph(G, copy=True, weight='weight'):
 if copy:
  G = (MultiDiGraph(G) if G.is_multigraph() else DiGraph(G))
 degree = dict(G.out_degree(weight=weight))
 for (u, v, d) in G.edges(data=True):
  if (degree[u] == 0):
   d[weight] = 0
  else:
   d[weight] = (d.get(weight, 1) / degree[u])
 return G

@ not_implemented_for ( 'undirected' ) def stochastic_graph ( G , copy = True , weight = 'weight' ) : if copy : G = ( MultiDiGraph ( G ) if G . is_multigraph ( ) else DiGraph ( G ) ) degree = dict ( G . out_degree ( weight = weight ) ) for ( u , v , d ) in G . edges ( data = True ) : if ( degree [ u ] == 0 ) : d [ weight ] = 0 else : d [ weight ] = ( d . get ( weight , 1 ) / degree [ u ] ) return G
returns a right-stochastic representation of directed graph g .