本文整理汇总了Python中networkx.Graph.has_node方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.has_node方法的具体用法?Python Graph.has_node怎么用?Python Graph.has_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.Graph
的用法示例。
在下文中一共展示了Graph.has_node方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Network
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import has_node [as 别名]
#.........这里部分代码省略.........
# thanks to Aric Hagberg
for u,v,d in self.graph.edges(data=True):
self.graph[u][v]['weight']=d[weight_key]
nodes = [(lambda nmod:'n'+str(nmod))(node) for node in range(1,nr_nodes + 1)]
from networkx import to_numpy_matrix
return to_numpy_matrix(self.graph, nodelist = nodes)
def toggle_surface(self):
""" Toggle the surface for the selected network nodes """
if self.rendermanager is None:
raise Exception('No RenderManager. You have to first activate the network and render it.')
self.rendermanager._toggle_surface()
def show_surface(self):
""" Shows the surface for the selected network nodes """
if self.rendermanager is None:
raise Exception('No RenderManager. You have to first activate the network and render it.')
self.rendermanager._show_surface()
def load_pickled_graphml(self, graph):
""" Loads a pickled GraphML file
Parameters
----------
graph : NetworkX Graph instance
A graph instance
"""
# setting the graph
self.graph = graph
if self.graph.has_node('n0'):
if self.graph.node['n0'].has_key('nodekeys'):
# extracting the node keys from the first node
self.nodekeys = self.graph.node['n0']['nodekeys']
# extracting the edge keys from the first edge (without explanation)
if self.graph.node['n0'].has_key('edgekeys'):
self.edgekeys = self.graph.node['n0']['edgekeys']
if self.graph.node['n0'].has_key('graphid'):
self.networkid = self.graph.node['n0']['graphid']
# remove node
self.graph.remove_node('n0')
def _return_default_edgevalue(self, edgekeys, key):
""" Looks up if there is a default value defined, otherwise
return zero """
if edgekeys[key].has_key('default'):
return float(edgekeys[key]['default'])
else:
return 0.0
def parse_network_graphml(self, path):
""" Read network in GraphML format from a path.
Parameters
----------
path : string
path the the GraphML file
Returns
-------
示例2: LangGraph
# 需要导入模块: from networkx import Graph [as 别名]
# 或者: from networkx.Graph import has_node [as 别名]
#.........这里部分代码省略.........
return types
def allEdgeTypes(self):
"""
Returns all the edge types
"""
results = set()
#collect all the edges with all the types
for s,e,types in self.allEdges():
#look up the edge types to make sure everything is covered
for edgeType in types:
results.add(edgeType)
#add in the reverse types
for edgeType in self.edgeTypes(e,s):
results.add(edgeType)
return results
def allEdges(self):
"""
Yield all the edges in the graph
"""
for start, end in self.graph.edges():
yield start, end, self.edgeTypes(start, end)
def contains(self, instance):
"""
Returns true if the graph contains the instance
"""
return self.graph.has_node(instance)
def instances(self):
"""
Return all the instances in the graph
"""
return self.graph.nodes()
def edges(self, instance):
"""
Returns all the edges connected to this instance
"""
inst = self.indexToInst(instance)
#make get the directed edges
if self.isDirected:
results = [t for _, t in self.graph.out_edges(inst)] + [t for t, _ in self.graph.in_edges(inst)]
else:
results = self.graph.adj[inst]
return results
def docType(self):
"""
Returns the document type (String)
"""
return self.temporal[0].event.docType
def adj(self, instance, type=None):
"""
Returns the adjancent node with a given type
"""
return [other for other in self.edges(instance)