4列数据取前两列 小记
import time import os import math import sys import os,os.path,shutil import numpy as np import re txtPath = 'F:/project/Breast/InBreast/INBreast/AllTXTxd/' txtType = 'txt' txtLists = os.listdir(txtPath) #列出文件夹下所有的目录与文件 print(txtLists) # Read the points(before 11:30,712) # Convert points to digital form(before 2:30,712) # Obtain the right batch(before 5.00, 712) for filename in txtLists: with open(txtPath + filename, 'r') as file: lines = file.readlines() dataset = [[] for i in range(len(lines))] for i in range(len(dataset)): dataset[i][:] = (item for item in lines[i].strip().split(',')) # 逐行读取数据 print("dateset:", dataset) # print(type(dataset[0][0])) # print(dataset.__sizeof__()) u = np.array(dataset) for i in range(u.shape[0]): # print(u[i,0][0]) findNumber = u[i,0].find(" ") # print(findNumber) x = round(float(u[i, 0][0:findNumber])) findNumber1 = u[i, 0][findNumber+1:].find(" ") y = round(float(u[i, 0][findNumber+1: findNumber + findNumber1])) print(x,y)