使用numpy的小惊喜
今天使用 numpy.true_divide 发现个有趣的事情,
下面的代码18、19行如果去掉,就会报下面的 RuntimeWarning
def multivalue_divide(timeseries):
# Get the last one day
timeseries = [ item for item in timeseries if item[0]>(timeseries[-1][0]-86400) ]
series = np.array([x[1] for x in timeseries])
window = 3
threshold = 0.5
remainder = series.size % window
if 0 != remainder:
series = series[remainder:]
series = series.reshape((series.size/window,window))
sum_arr = np.sum(series,axis=1)
# The test statistic is infinite when the median is zero,
# so it becomes super sensitive. We play it safe and skip when this happens.
if 0 == sum_arr[-2]:
return False
divide = np.true_divide(sum_arr[-1],sum_arr[-2])
return True if np.abs(divide-1) > threshold else False
RuntimeWarning
/data/skyline/src/analyzer/algorithms.py:320: RuntimeWarning: invalid value encountered in true_divide
divide = np.true_divide(sum_arr[-1],sum_arr[-2])
加上对除数是否为0的判断就可以了,是不是说明numpy有一个自动检查的过程?
使用numpy的小惊喜的更多相关文章
- Numpy的小总结
1.Numpy是什么? numpy是Python的一个科学计算库,提供矩阵运算的功能. 1.1Numpy的导入 import numpy as np #一般都是用numpy的别名来进行操作 1.2Nu ...
- Intellij IDEA神器居然还有这些小技巧
概述 Intellij IDEA真是越用越觉得它强大,它总是在我们写代码的时候,不时给我们来个小惊喜.出于对Intellij IDEA的喜爱,我决定写一个与其相关的专栏或者系列,把一些好用的Intel ...
- Intellij IDEA神器值得收藏的小技巧
概述 Intellij IDEA真是越用越觉得它强大,它总是在我们写代码的时候,不时给我们来个小惊喜.出于对Intellij IDEA的喜爱,我决定写一个与其相关的专栏或者系列,把一些好用的Intel ...
- 细数Windows 的那些小技巧!
以下整理自知乎 Windows 有哪些你相见恨晚的技巧?和Quora(英文版) What are some secret tricks you should know about Windows? 等 ...
- 【转载】Intellij IDEA神器居然还有这些小技巧
概述Intellij IDEA真是越用越觉得它强大,它总是在我们写代码的时候,不时给我们来个小惊喜.出于对Intellij IDEA的喜爱,我决定写一个与其相关的专栏或者系列,把一些好用的Intell ...
- 6 个珍藏已久 IDEA 小技巧,这一波全部分享给你!
每周趣图 产品经理设计体验/用户实际体验 本周就不写技术分析文章了,分享几个珍藏已久的 IDEA 的「骚技巧」,助你快速完成代码. 还等什么?赶紧上车吧...... 先赞后看,养成习惯.微信搜索「程序 ...
- 如何通过官方渠道为Windows 10 添加具有中国特色的字体
Windows 10的变化细节上个人认为要比Windows 8多很多,而且很多功能找到之后还是小惊喜,就是挺多好用的地方居然都不正经宣传一下,微软真是搞得悄悄地干活? 今天为大家介绍一下通过官方途径添 ...
- [转载]jquery版小型婚礼(可动态添加祝福语)
原文链接:http://www.cnblogs.com/tattoo/p/3788019.html 前两天在网上不小心看到“js许愿墙”这几个字,我的神经就全部被调动了.然后就开始我 的百度生涯,一直 ...
- 优秀网站看前端 —— 小米Note介绍页面
刚开始经营博客的时候,我写过不少“扒皮”系列的文章,主要介绍一些知名站点上有趣的交互效果,然后试着实现它们.后来开始把注意力挪到一些新颖的前端技术上,“扒皮”系列便因此封笔多时.今天打算重开“扒皮”的 ...
随机推荐
- CENTOS重新安装JDK
centos 删除默认安装的JDK 重新安装JDK 1.删除JDK 通过xshell工具成功连接安装好的虚拟机之后可通过 rpm -qa | grep java 或 rpm -qa | gre ...
- 解决在使用gensim.models.word2vec.LineSentence加载语料库时报错 UnicodeDecodeError: 'utf-8' codec can't decode byte......的问题
在window下使用gemsim.models.word2vec.LineSentence加载中文维基百科语料库(已分词)时报如下错误: UnicodeDecodeError: 'utf-8' cod ...
- 初识Haskell 二:基本操作符、类型Type、数据结构
对Discrete Mathematics Using a Computer的第一章Introduction to Haskell进行总结.环境Windows 1. 在安装了ghci后,便可以进行Ha ...
- 使用eclipse启动tomcat里的项目时报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
1.这种错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener刚开始看的时候 ...
- mybatis将传入的Integer类型的0被识别成空字符串的问题
更改mapper文件的sql如下: <if test="interger != null"> interger= #{interger} </if> 原因: ...
- win 执行puppet
C:\scripts\win_exec_proxy.bat \\adsoft.base-fx.com\puppet\puppet\files\Windows_10_x64\C\user\logon\ ...
- randperm
randperm是matlab函数,功能是随机打乱一个数字序列. 函数功能:随机打乱一个数字序列. 语法格式: y = randperm(n) y是把1到n这些数随机打乱得到的一个数字序列. 程序示例 ...
- hdu-4635(tarjan缩点)
题意:先给你一个n个点,m条边的有向图,问你最多能够增加多少条边,使得这个图不是一个强连通图 解题思路:考虑最多要添加的边数,所以如果能把初始图划分成两个部分,每个部分都是完全图,这两个部分分别用单向 ...
- reload ans current configure command
reload ans current configure command enable_ans_license.conf enable ans license WL enable ans licens ...
- [POI2015]KIN[线段树]
很套路的维护最大和子段 #include <cmath> #include <cstring> #include <cstdio> #include <cst ...