当前位置:网站首页>从sparse.csc.csr_matrix生成邻接矩阵
从sparse.csc.csr_matrix生成邻接矩阵
2022-07-06 11:36:00 【NorburyL】
需要photo.edglist和cs.edglist
solution1
通过输出str,和str的操作过滤。
result
fail,不能完全获取到数据,部分结点的链接结点太多了,表示不出来。
code
import scipy
from edglist_utils import load_network_data
from scipy import sparse
network_file = 'photo'
adj, features, Y = load_network_data('graphsage/input/' + network_file + '.mat')
f2 = open("graphsage/cora_adj_list.txt", 'w')
f1 = open("graphsage/cora_create_list.txt", 'w')
# for i in range(2708):
# f2.write(str(i) + "\n" + str(adj[i]) + "\n\n")
# for part in adj[i]:
#
#
# part = str(part).replace(' (0, ', '')
# part = str(part).replace(') 1', '')
# part = str(part).replace(' : :\n', '')
# # list_str = list(str(part)) # 将字符串转换为列表
# # print(str(i)+","+part)
# quote_list = part.split('\n')
# for quote in quote_list:
# if (i < int(quote)) :
# f1.write(str(i) + "," + str(quote)+"\n")
# print(str(i) + "," + str(quote))
solution2
将ndarray 与 scipy.sparse.csc.csr_matrix 的互转
url
https://huwang.blog.csdn.net/article/details/84623786?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-84623786-blog-83036442.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-84623786-blog-83036442.pc_relevant_default&utm_relevant_index=2
result
成功
code
import scipy
from edglist_utils import load_network_data
from scipy import sparse
network_file = 'cs'
adj, features, Y = load_network_data('graphsage/input/' + network_file + '.mat')
f1 = open("graphsage/cs_create_list.txt", 'w')
my_matrix = scipy.sparse.csc_matrix(adj)
my_array = my_matrix.A
print(type(my_array))
print(len(my_array))
print(int(my_array[2][1]))
for i in range(len(my_array)):
for j in range(len(my_array)):
if int(my_array[i][j]) == 1 and i < j:
f1.write(str(i) + "," + str(j) + "\n")
边栏推荐
- 数学知识——高斯消元(初等行变换解方程组)代码实现
- 潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
- 冒烟测试怎么做
- An error occurs when installing MySQL: could not create or access the registry key needed for the
- 【翻译】供应链安全项目in-toto移至CNCF孵化器
- About image reading and processing, etc
- A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
- Translation D28 (with AC code POJ 26:the nearest number)
- Reflection and illegalaccessexception exception during application
- IC设计流程中需要使用到的文件
猜你喜欢
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
ROS custom message publishing subscription example
Help improve the professional quality of safety talents | the first stage of personal ability certification and assessment has been successfully completed!
Don't miss this underestimated movie because of controversy!
如何自定义动漫头像?这6个免费精品在线卡通头像生成器,看一眼就怦然心动!
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
接雨水问题解析
Druid 数据库连接池 详解
Pytorch common loss function
随机推荐
LeetCode-1279. Traffic light intersection
【翻译】云原生观察能力微调查。普罗米修斯引领潮流,但要了解系统的健康状况仍有障碍...
Mind map + source code + Notes + project, ByteDance + JD +360+ Netease interview question sorting
A method of removing text blur based on pixel repair
MATLAB中deg2rad和rad2deg函数的使用
Mysql Information Schema 學習(一)--通用錶
1805. 字符串中不同整数的数目
第五期个人能力认证考核通过名单公布
R language uses the order function to sort the dataframe data, and descending sorting based on a single field (variable)
Live broadcast today | the 2022 Hongji ecological partnership conference of "Renji collaboration has come" is ready to go
五金机电行业供应商智慧管理平台解决方案:优化供应链管理,带动企业业绩增长
DaGAN论文解读
快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数
CPU负载很低,loadavg很高处理方法
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
关于图像的读取及处理等
PMP practice once a day | don't get lost in the exam -7.6
Lick the dog until the last one has nothing (simple DP)
时钟轮在 RPC 中的应用
Simple application of VBA script in Excel