我正在研究一个类似于随机游走的项目,目前我正在尝试找出是否可能,如果可能的话如何找出有向networkx图中的节点是否“悬空”,即如果它没有到其他节点的边。
import collections
import networkx as nx
import numpy as np
import random as rand
from collections import Counter
def randomSurf(G, moves): #with G as a directed graph and moves as the amount of "random walks"
#rand.seed(15) #Random seed for testing consistency
starter = rand.choice(list(G.nodes))
currNode = starter
m = 0.15
#Construct list of dangling nodes
list_of_dangl = [] #<- this is where I'm struggling.
list_of_nodes = [starter] #List of all visited nodes, with the starting node already in it. …Run Code Online (Sandbox Code Playgroud)