【发布时间】:2019-10-07 10:12:54
【问题描述】:
我正在研究构建 GCN,现在我在下面实现此代码。
我在 jupyternotebook 上运行它。
在[1]中
import numpy as np
from networkx import karate_club_graph, to_numpy_matrix
zkc = karate_club_graph()
order = sorted(list(zkc.nodes()))
A = to_numpy_matrix(zkc, nodelist=order)
I = np.eye(zkc.number_of_nodes())
A_hat = A + I
D_hat = np.array(np.sum(A_hat, axis=0))[0]
D_hat = np.matrix(np.diag(D_hat))
在[2]中
X = np.matrix([
[i, -i]
for i in range(A.shape[0])
], dtype=float)
在[3]中
W = np.matrix([
[1, -1],
[-1, 1]
])
在[4]中
W_1 = np.random.normal(
loc=0, scale=1, size=(zkc.number_of_nodes(), 4))
W_2 = np.random.normal(
loc=0, size=(W_1.shape[1], 2))
在[5]中
def gcn_layer(A_hat, D_hat, X, W):
return D_hat**-1 * A_hat * X * W
H_1 = gcn_layer(A_hat, D_hat, I, W_1)
H_2 = gcn_layer(A_hat, D_hat, H_1, W_2)
output = H_2
在[6]中
feature_representations = {
node: np.array(output)[node]
for node in zkc.nodes()}
这是所有代码,我想创建这样的图形,但我不知道如何使用数组来绘制它 关于 matplotlib.pyplot 谢谢。
【问题讨论】:
-
您尝试过简单的散点图吗?它适用于数组matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.scatter.html
标签: python arrays matplotlib