现有的数据格式:
1 2
4 5
3 4
目标格式:
0 0 0 0 0 0
0 0 1 0 0 0
0 1 0 0 0 0
0 0 0 0 1 0
0 0 0 1 0 1
0 0 0 0 1 0
代码:
import numpy as np
b = np.zeros((6, 6))
ft = open("kk.txt", "r")
lines = ft.readlines()
for line in lines:
a = list(line.rstrip().split(" "))
b[int(a[0])][int(a[1])]=1
b[int(a[1])][int(a[0])]=1
ft.close()
print(b)
np.savetxt("faa.txt", b, fmt="%d")