↓ 跳过正文
  1. Posts/

使用python计算误差代码

·126 字·1 分钟

import os

 1import math
 2ave_err=0.0
 3max_err=0.0
 4max_err_rate=0.0
 5length=0
 6with open("cpu_result.txt","r") as fp1, open("cuda_ppl_result.txt","r") as fp2:
 7    for l1 in fp1:
 8        l2 = fp2.readline()
 9        l1=l1[:-2]
10        l2=l2[:-2]
11        lst = l1.split(' ')
12        lst2 = l2.split(' ')
13        #print lst
14        lst = [float(x) for x in lst ]
15        length = length + len(lst)
16        lst2 = [float(x) for x in lst2]
17        #print (lst)
18        #print (lst2)
19
20        for index,x in enumerate(lst):
21            y = lst2[index]
22            ave_err = ave_err + abs(x-y)
23            max_err = max(max_err,abs(x-y))
24            max_err_rate = max(max_err_rate,abs(x-y)/x)
25
26    print("len=",length)
27    print("max_err=",max_err)
28    print("max_err_rate=",max_err_rate*100,"%")
29    print("ave_err=",ave_err/length)

需要提供两个文件,并且两个文件的数据格式相同。

相关文章

正则匹配中文及常用正则表达式 (转载)

·1078 字·3 分钟
先放一个同事安利给我的网站:regex101 查询匹配的中文字符unicode编码 正则表达式用于字符串处理、表单验证、日志数据分析等场合,实用高效。现将自己走网上搜索并总结的常用方法收集了一下: 匹配中文字符的正则表达式: [\u4e00-\u9fa5] 注:匹配中文还真是个头疼的事,有了这个表达式就好办了

python只获取当前目录下的文件夹及文件名

·237 字·1 分钟
list = os.listdir(rootdir)#列出目录下的所有文件和目录 1for line in list: 2 filepath = os.path.join(rootdir,line) 3 if os.path.isdir(filepath):#如果filepath是目录 4 print "dir:" + filepath 5 else: 6 print "file:" + filepath 如果需要遍历文件夹下的所以文件,可以使用os.walk()方法。

python numpy 用法 简明手册

·8276 字·17 分钟
原文链接 感谢stanford,感谢原作者的翻译,我调整了一下代码格式,可以当做手册来用了,毕竟之前没怎么写过py 23333 译者注:本文智能单元首发,翻译自斯坦福CS231n课程笔记Python Numpy Tutorial,由课程教师Andrej Karpathy授权进行翻译。本篇教程由杜客翻译完成,Flood Sung、SunisDown、巩子嘉和一位不愿透露ID的知友对本翻译亦有贡献。

libgfortran.so.4 missing under archlinux

·919 字·2 分钟
。。。哭了哦,终于解决了这个 bug 参考资料: libgfortran broken? libgfortran=3.0 should not be install with numpy <= 1.9 [SOLVED] libgfortran.so.3:cannot open shared object file: No such file [Replacing gcc-libs-libs with gcc-multilib arch conflict with gcc-libs and gcc-libs-multilib on latest update 一开始以为是 anaconda 相关,搞了半天。 然后又按照第一个资料里说的,试图把 libgfortran 用 libgcc 替代。

conda升级anaconda ValueError的解决办法

·121 字·1 分钟
conda update anaconda 后提示 1ValueError: unsupported format character ')' (0x29) at index 49 查到了这个:anaconda update issue I have narrowed this down to the following packages: package build psutil-1.2.1 py27_0 hard-link pycparser-2.10 py27_0 hard-link pykit-0.1.0 np18py27_2 hard-link pyparsing-2.0.1 py27_0 hard-link by calling "conda install anaconda" and then successfully installing everything else one at a time. These four packages consistently exhibit the described behaviour. (note: pykit depends on pycparser so may itself be ok - can't tell) 我先把psutil卸载掉,重新update了一下,成功。