python中有两种方法判断一个数是不是偶数或者奇数: In [29]: 3&1 Out[29]: 1 In [30]: 3%2 Out[30]: 1 In [31]: 4&1 Out[31]: 0 In [32]: 4%2 Out[32]: 0 当不知道 采用 % 或 & 哪种 判断 奇偶的方法运行效率更高的时候 利用python timeit来测定 二进制与操作&1判断偶奇数: def test1(x): for r in range(1,x): if r&1:
其实平时使用测试应用运行时间的情况 细算一下还真的很少.很久没有做性能优化的工作,不管是cProfile还是timeit模块都已经生疏了很久没有使用,我在以前的文章里面有提到过cPfile的性能测试使用,但是一直没有使用过这个更轻量级的运行时间测量库进行过仔细实践总结,今天就来总结一下. 从最简单的例子开始,比如我们想测试一个列表推导式究竟要比正常写for快多少. import timeit foooo = """ sum = [] for i in range(1000):
//有时候,我们想知道一个函数的计算耗时,那么,你可以用timeit //test.py 1 import timeit 2 3 def func(): 4 s = 0 5 for i in range(1000): 6 s += i 7 pass 8 9 def test_range(n): 10 for i in range(n): 11 pass 12 13 de
本文是转发自:https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/ 的一篇文章,先记录在此,等有空时我会翻译成中文. 如果有读者看到该文,支持看原文. 原文内容如下: 27 Jupyter Notebook tips, tricks and shortcuts 12 OCT 2016 in resources and guides This post originally appeared on Alex Ro
原文首发于个人博客https://kezunlin.me/post/c50b0018/,欢迎阅读! Brewing Logistic Regression then Going Deeper. Brewing Logistic Regression then Going Deeper While Caffe is made for deep networks it can likewise represent "shallow" models like logistic regress