当前位置:网站首页>从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")
边栏推荐
- 数学知识——高斯消元(初等行变换解方程组)代码实现
- R language ggplot2 visualization: use ggviolin function of ggpubr package to visualize violin diagram
- Dark horse -- redis
- Tensorflow and torch code verify whether CUDA is successfully installed
- tensorflow和torch代码验证cuda是否安装成功
- CCNP Part 11 BGP (III) (essence)
- Mysql Information Schema 学习(一)--通用表
- Analysis of frequent chain breaks in applications using Druid connection pools
- Solution of intelligent management platform for suppliers in hardware and electromechanical industry: optimize supply chain management and drive enterprise performance growth
- Swagger2 reports an error illegal DefaultValue null for parameter type integer
猜你喜欢
zabbix 代理服务器 与 zabbix-snmp 监控
潇洒郎: AttributeError: partially initialized module ‘cv2‘ has no attribute ‘gapi_wip_gst_GStreamerPipe
五金机电行业智能供应链管理系统解决方案:数智化供应链为传统产业“造新血”
Detailed idea and code implementation of infix expression to suffix expression
保证接口数据安全的10种方案
凤凰架构3——事务处理
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
spark基础-scala
Black Horse - - Redis Chapter
黑馬--Redis篇
随机推荐
时钟轮在 RPC 中的应用
Dark horse -- redis
黑馬--Redis篇
【翻译】数字内幕。KubeCon + CloudNativeCon在2022年欧洲的选择过程
Swagger2 reports an error illegal DefaultValue null for parameter type integer
面试突击63:MySQL 中如何去重?
包装行业商业供应链管理平台解决方案:布局智慧供应体系,数字化整合包装行业供应链
Help improve the professional quality of safety talents | the first stage of personal ability certification and assessment has been successfully completed!
Php+redis realizes the function of canceling orders over time
[玩转Linux] [Docker] MySQL安装和配置
Meilu biological IPO was terminated: the annual revenue was 385million, and Chen Lin was the actual controller
Elastic search indexes are often deleted [closed] - elastic search indexes gets deleted frequently [closed]
系统性详解Redis操作Hash类型数据(带源码分析及测试结果)
Mysql Information Schema 學習(一)--通用錶
ROS custom message publishing subscription example
JDBC详解
学习探索-函数防抖
CCNP Part 11 BGP (III) (essence)
[translation] a GPU approach to particle physics
USB host driver - UVC swap