将数据和对应的真值拼到一行,生成新的txt文件。比如这种形式
with open('aug_data.txt', 'r') as f:
list_train = f.readlines()
# 读成了列表形式。
with open('aug_gt.txt', 'r') as f:
list_test = f.readlines()
with open('train_all.txt', 'w') as f:
for i, train in enumerate(list_train):
train = train.strip('\n')
# 去掉每一行中的空格,这样才可以读成一列
test = list_test[i].strip('\n')
result = str(train) + " " + str(test) + '\n' #6个空格
f.write(result)