# -*- coding: utf-8 -*-
import numpy as np
def readData(file,cols):
file=open(file)
lines=file.readlines()
rows=len(lines)
datamat = np.zeros((rows,cols))
row=0
for line in lines:
line=line.strip().split('\t')
datamat[row,:]=line[::]
row+=1
return datamat
#data = readData("data_train.txt",13)
#data = readData("data_test.txt",13)
#data = readData("data_train_labels.txt",2)
data = readData("data_test_labels.txt",2)
print(data)
print(data.shape)
python读取txt文件封装方法版
最新推荐文章于 2023-10-06 19:23:51 发布