igraph load 无法读取保存的graph attr

啥b igraph

igraph.load无法从igraph.save的图中读取保存的graph attr。必须要自己再另外写一个接口来读取,接口给您:

def FUCK_U_IGraphLoad(path,graph_attr_num):
    with open(path, "r") as f:
        data=f.readlines()
        count=0
        for line in data:
            gattr=line.split()
            if gattr[0]=="label":
                label=int(gattr[1])
                count+=1
            if gattr[0]=="feature":
                feature=line.split("feature")[1]
                count+=1
            if count==graph_attr_num:
                return label, feature

label,feature=FUCK_U_IGraphLoad("G_N2_E2_NL1_GL5_18.gml")
print(label,feature)
>>>0  "[' 22.000000, 32.941603, 75.110000,  1.700000,  3.405000,188.800000,  6.000000, 11.000000,  5.000000,  9.000000,  5.000000,  8.000000,  9.000000,  4.000000,  9.000000,  6.000000, 11.000000,  5.000000\n', ' 24.000000, 30.484920, 79.090000, -4.430000,  3.513000,221.700000,  9.000000,  9.000000,  6.000000, 11.000000,  8.000000,  5.000000,  6.000000,  7.000000, 11.000000,  8.000000, 10.000000,  6.000000\n']"

再利用上一篇将这里的string feature转化成float feature即可。

这里的graph数据如下,可根据自己的实际数据修改if判断部分

Creator "igraph version 0.9.4-24-gb29e741ea Mon Sep 19 22:09:29 2022"
Version 1
graph
[
  directed 1
  feature "[' 22.000000, 32.941603, 75.110000,  1.700000,  3.405000,188.800000,  6.000000, 11.000000,  5.000000,  9.000000,  5.000000,  8.000000,  9.000000,  4.000000,  9.000000,  6.000000, 11.000000,  5.000000\n', ' 24.000000, 30.484920, 79.090000, -4.430000,  3.513000,221.700000,  9.000000,  9.000000,  6.000000, 11.000000,  8.000000,  5.000000,  6.000000,  7.000000, 11.000000,  8.000000, 10.000000,  6.000000\n']"
  label 5
  node
  [
    id 0
    label 0
  ]
  node
  [
    id 1
    label 0
  ]
  edge
  [
    source 1
    target 0
    label 0
    key 0
  ]
  edge
  [
    source 0
    target 1
    label 0
    key 0
  ]
]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值