標籤:

處理成首尾連接分叉列表

import numpy as npdata = np.loadtxt(txt文件\所有坐標數據構成的數組.txt)np.set_printoptions(threshold=np.inf) #輸出全部矩陣不帶省略號x1_y1 = data[:,(0,1)]x2_y2 = data[:,(2,3)]# print(data.tolist().shape)datalist = data.tolist()####################################首尾相連列表shouwei = []for i in range(0,(len(datalist)-1),2): if datalist[i][2:4] == datalist[i+1][0:2]: shouwei.append(datalist[i]+datalist[i+1])# with open(txt文件\首尾相連列表.txt,a) as f:# f.write(str(shouwei)+
)
###################################### 排序sortdata = sorted(datalist)# print(sortdata)fencha = []for i in range(len(sortdata)-1): if sortdata[i][0:2] == sortdata[i+1][0:2]: fencha.append(sortdata[i]+sortdata[i+1])shouwei = np.array(shouwei)fencha = np.array(fencha)swfc = np.concatenate((shouwei,fencha),axis=0)print(swfc.shape)print(shouwei.shape)# print(fencha)np.savetxt(txt文件\首尾相連分叉列表.txt,swfc)with open(txt文件\首尾相連分叉.txt,a) as f: f.write(str(swfc)+
)########################################### with open(txt文件\坐標列表.txt,a) as f:# f.write(str(data) +
)

推薦閱讀:

Python|絕不亂入的靠譜書單
Python錯誤及異常總結匯總
薦書:《Fluent Python》
Python 實戰:股票數據定向爬蟲
linux如何高效的學習語言編程?

TAG:Python |