NetworkX到GraphLab连接组件转换

时间:2016-02-18 18:29:20

标签: python networkx graphlab

与以下NetworkX代码等效的GraphLab是什么?
for nodeset in nx.connected_components(G):

在GraphLab中,我想为每个连接的组件获取一组顶点ID。

2 个答案:

答案 0 :(得分:1)

# Make a graph with two components. import graphlab G = graphlab.SGraph().add_edges( [graphlab.Edge(i, i+1) for i in range(3)]) G = G.add_edges([graphlab.Edge(i, i+1) for i in range(4, 6)]) # Get the connected components. cc = graphlab.connected_components.create(G) # Find the vertices for a given component (0, in this example). nodes = cc.component_id.filter_by(0, 'component_id') print nodes +------+--------------+ | __id | component_id | +------+--------------+ | 5 | 0 | | 6 | 0 | | 4 | 0 | +------+--------------+ [3 rows x 2 columns] 返回的组件ID采用SFrame的形式,因此获取给定组件ID的最简单方法是过滤SFrame:

class Appointment < ActiveRecord::Base
  include Appointments::Events

  ALERT = "hello!"

end

答案 1 :(得分:0)

这是从NetworkX移植到GraphLab的第一个切入点。但是,迭代看起来很慢 temp1 = cc['component_id']
temp1.remove_column('__id')
id_set = set()
id_set = temp1['component_id']
for item in id_set:
  nodeset = cc_out[cc_out['component_id'] == item]['__id']