python加载txt数据 矩阵

 

python加载txt数据  矩阵

def loadDataKVSet(fileName):  
    dataMat = []              
    
    fr = open(fileName,'r', encoding='utf-8')
    for line in fr.readlines():
        curLine = line.strip().split(',')
        a_float = []
        for num in curLine:
            a_float.append(num)
        #fltLine = map(float, curLine)    # 将每个元素转成float类型
        dataMat.append(a_float)
        
    return dataMat

 

 

 

##############################33

posted @ 2021-06-05 21:31  西北逍遥  阅读(152)  评论(0编辑  收藏  举报