
图神经网络
zjc4j
打工人
展开
-
pytorch+numpy实现--获取每行中数据大于平均值的数据,将其提取出来转化为稀疏矩阵
代码import torchx = torch.randn(3,4)print(x)print(torch.mean(x,dim=1,keepdim=True))mz_items = x[:,] > torch.mean(x,dim=1,keepdim=True)print(mz_items)import numpy as npmz_items_np = mz_items.numpy()index = np.argwhere( mz_items_np == True )print(原创 2021-11-21 21:54:16 · 1635 阅读 · 0 评论 -
scipy的稠密矩阵转为pytorch的稀疏矩阵
转换方法cipy稠密矩阵转换为scipy的稀疏矩阵方法为scipy.sparse,scipy的稀疏矩阵转为稠密矩阵的方法,直接.todense()pytorch的稀疏矩阵转为稠密矩阵.to_dense(),稠密矩阵转稀疏矩阵torch.sparse.FloatTensor(i, v, coo.shape)代码 def _convert_sp_mat_to_sp_tensor(self, X): # scipy稠密矩阵转换为scipy的稀疏矩阵方法为scipy.sparse,sc原创 2021-11-14 21:40:01 · 2405 阅读 · 0 评论 -
Python 主对角线随机赋值,并转为稀疏矩阵存储方式存储
问题用Python将主对角线随机赋值,并转为稀疏矩阵存储方式存储。代码import numpy as np#3×3的单位矩阵a = np.eye(50 + 100)#获取主对角线元素的索引row, col = np.diag_indices_from(a)nums = np.random.randn(150)a[row,col] = numsprint(a)# a[row, col] = [3, 3, 3]diag_mat = sp.dok_matrix((50 + 100, 50原创 2021-11-12 21:29:59 · 989 阅读 · 0 评论 -
python ThreadPool多线程的操作案例
需求做实验的时候,为了加速处理数据的速度,采用多线程的方式来实现。实现from multiprocessing.dummy import Pool as ThreadPoolfrom collections import defaultdicturiv = defaultdict(list)def aas(): global b b =[2]def process(item): i = item[0] a = item[1] c = a + b[0]原创 2021-10-22 17:46:14 · 329 阅读 · 0 评论 -
Python 字典转json保存到文件中,再从json文件中读取数据,转为字典,再将带图结构的数据存入字典
需求做实验的需求,字典转json保存到文件中,再从json文件中读取数据,转为字典,再将带图结构的数据存入字典,最后按key排序输出。实现test = {}testr = {}for u in [2,4,1,0,3]: for r in range(2): testiv = {} for i,v in zip([100,101,102],[200,201,202]): testiv[i]=v testr[r]=test原创 2021-10-22 17:39:59 · 574 阅读 · 0 评论 -
Python 字典中随机删除数据
需求在做实验时候需要随机删除一些节点,也即需要随机删除字典中某些数据。具体实现如下。实现import randomtest = {}testr = {}for u in [2,4,1,0,3]: for r in range(2): testiv = {} for i,v in zip([100,101,102],[200,201,202]): testiv[i]=v testr[r]=testiv原创 2021-10-22 17:22:33 · 1487 阅读 · 0 评论 -
python multiprocessing.pool NameError: name is not defined
问题论文代码遇到类似下面的问题,经过一番努力算是解决这个问题吧。# import torch# # print(torch.__version__)# # print(torch.cuda.is_available())import multiprocessingcores = multiprocessing.cpu_count() // 2def b(xs): t = temp_num[xs[0]] * 2 return tdef a(): global temp原创 2021-10-12 14:03:51 · 2302 阅读 · 3 评论 -
什么是Inductive Learning & Transductive Learning?
阅读论文时,看到Inductive Learning 和 Transductive Learning时不是很懂。通过阅读书籍知道了其含义,在此记录下。 归纳学习(Inductive Learning )是指可以对在训练阶段见不到的数据直接进行预测而不需要重新训练的学习方法。转导学习(Transductive Learning)是指所有的数据在训练阶段都可以拿到,学习过程是作用在这个固定的数据上的,一旦数据发生改变,需要重新进行学习训练,典型的比如图上的随机游走算法,一旦图数据发生变动,所以节点的表示..原创 2020-11-29 20:21:57 · 1471 阅读 · 1 评论