python读取txt文件中的数组

写此博客只是为做笔记


def read_data(dir_str):
    '''
    此函数读取txt文件中的数据
    数据内容:科学计数法保存的多行两列数据
    输入:txt文件的路径
    输出:小数格式的数组,行列与txt文件中相同
    '''
    data_temp=[]
    with open(dir_str) as fdata:
        while True:
            line=fdata.readline()
            if not line:
                break
            data_temp.append([float(i) for i in line.split()])
    return np.array(data_temp)

你可能感兴趣的:(python)