如何在Python中正确索引元素?

问题描述

我正在尝试实现以下功能来训练神经网络,如下所示:

        # Here I am trying to convert train edges to nx.graph

       data.edge_index = torch.from_numpy(edges(data._train)).long()
        G = nx.Graph()
        edge_numpy = data.edge_index.numpy()
        edge_list = []

        for i in range(data.num_edges):
        edge_list.append(tuple(edge_numpy[:,i]))
    G.add_edges_from(edge_list)
    data.G = G

    # These are nodes from training graph
    nodes = list(G.nodes())

    new = []

    # These are features for the whole graph
    feature = data.x.detach().cpu().numpy()

    # Here the all set is calculated from all nodes in whole graph
    all = get_seedsets(data.num_nodes,c=0.5)
    print(all)..... [array([5,1,2]),array([1])]

    for i in range(len(all)):
        temp_id = all[i]
        specific_features=np.zeros((feature.shape[0],feature.shape[1])

        # Here I am trying to copy features of each node in the all to specific_features
        for v in range(len(nodes)):
            y = nodes.index(v).........*ValueError: 180 is not in list*

            if y in temp_id:
                specific_features[nodes[v]] = feature[y]

但是,我遇到此错误

V`alueError:180不在列表中*

我该怎么办?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)