我目前正在使用PyG开发一个推荐系统.
edge_index = tensor([[ 0, 0, 0, ..., 9315, 9317, 9317],
[ 100, 448, 452, ..., 452, 1, 307]], device='cuda:0')}
edge_index[0]
包含学生索引,edge_index[1]
包含连接模块的索引(两者的长度相同).因此,edge_index[0][i]
是边缘i
的源 node ,edge_index[1][i]
是边缘i
的目的地.
在模型训练之后,我将生成一个2D张量recs
,形状为#of Students x#of Modules,值为0-1.0=不推荐,1=推荐.recs
可能是这样的:
recs = tensor([0.54, 0.23, 0.98, ..., 0.12, 0.43, 0.87],
...,
[0.43, 0.53, 0.12, ..., 0.92, 0.12, 0.53])
当然,如果学生已经学习了某个模块,我不想推荐它.有没有办法将原始图形的所有边设置为零,方法是使用PyG的edge_index
作为坐标或其他什么?
基本上,我想将特定值设置为recs
到0,如下所示:
for i in range(0, len(edge_index[0])):
recs[edge_index[0][i]][edge_index[1][i]] = 0
有没有办法使用张量函数来实现这一点?