欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python读取txt文件中的数组

程序员文章站 2024-01-05 14:53:16
...
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)

上一篇:

下一篇: