Python程序教程

您现在的位置是:首页 >  Python

当前栏目

python读取txt文件中的数组

python,读取,txt,文件,数组
2025-03-20 08:49:00 时间

大家好,又见面了,我是你们的朋友全栈君。

写此博客只是为做笔记

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)

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139543.html原文链接:https://javaforall.cn