开发者

scipy.stats.spearmanr: Warning: divide by zero encountered in divide

I use scipy.stats.spearmanr(a,b) and I get:

Warning: divide by zero encountered in divide

The operation ends corr开发者_如何学Cectly, but the warning is displayed. Both a and b are "normal" data, (no "zero-only" vectors etc.). Any idea what is the cause, or how to suspend the warning?

EDIT:

This is the offending line in spearmanr:

/usr/lib/python2.7/dist-packages/scipy/stats/stats.pyc in spearmanr(a, b, axis)
   2226     rs = np.corrcoef(ar,br,rowvar=axisout)
   2227 
-> 2228     t = rs * np.sqrt((n-2) / ((rs+1.0)*(1.0-rs)))
   2229     prob = distributions.t.sf(np.abs(t),n-2)*2
   2230 


division by zero is by design, rs=1 on diagonal. This happens for any values.

However, in scipy 0.9 this error has been silenced locally within the spearmanr function. The corresponding sourceline contains

np.seterr(divide='ignore') # rs can have elements equal to 1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜