Код: Выделить всё
( node1, node2 ) = edge_value
Код: Выделить всё
{ ( node1, node2 ) : edge_value [, ... [, ... ] ] }
Код: Выделить всё
global
Код: Выделить всё
import networkx as nx
from multiprocessing import Pool
G = nx.Graph()
f_correlation = {}
Код: Выделить всё
( node1, node2 ) = edge_value
Код: Выделить всё
def construct_graph_parallelly(pair_with_df):
global G
global f_correlation
pair, df = pair_with_df
i, j = pair
# calculate the edge value and store it in the global variable f_correlation
f_correlation[ (i, j) ] = calculate_value(df, i, j) # this function calculate some value on the dataframe
# here i, j are node in the graph
G.add_edge(i, j, weight = f_correlation[ (i, j) ])
return f_correlation
Код: Выделить всё
def make_all_pair_with_df(node_list, df):
all_pair_with_df = []
for i in node_list:
for j in node_list:
if i != j :
pair_with_df = (i,j),df
all_pair_with_df.append(pair_with_df)
return all_pair_with_df
node_list = ['a', 'b', 'c', 'd', 'e']
pool = Pool()
all_pair_with_df = make_all_pair_with_df(node_list, df)
f_correlation = pool.map(construct_graph_parallelly, all_pair_with_df)
pool.close()
print("DONE")
Одной из проблем может быть
Код: Выделить всё
global
Но для моей работы мне нужно обновить словарь и Связанный граф
Strong> во всем мире.
Как я могу это сделать или какие изменения мне следует внести, чтобы это работало?
Подробнее здесь: https://stackoverflow.com/questions/650 ... rently-upd