2016-12-28 33 views
1

随着代码:SciPy的generic_filter投返回值

def stat_function(x): 
    center = x[len(x)/2] 
    ecdf = ECDF(xx) 
    percentile = (1 - ecdf(center)) * 100 
    print percentile 
    return percentile 

主:

print generic_filter(table, 
    function=stat_function, 
    size=window_size, 
    mode=mode, 
    extra_arguments=(-1,)) 

我得到的输出:

[[84 76 76 76 76 76 76 76 76 60] 
[52 48 48 48 48 48 48 48 48 39] 
[52 48 48 48 48 48 48 48 48 39] 
[52 48 48 48 48 48 48 48 48 39] 
[52 48 48 48 48 48 48 48 48 39] 
[52 48 48 48 48 48 48 48 48 39] 
[52 48 48 48 48 48 48 48 48 39] 
[52 48 48 48 48 48 48 48 48 39] 
[52 48 48 48 48 48 48 48 48 39] 
[24 15 15 15 15 15 15 15 15 0]] 

一切都很好,但如果我打印的“百分'在我的函数返回之前,我看到我所有的15s实际上是16.0s,而我的39s是40.0s。函数generic_filter需要re转动一个浮点数并返回“16.0”,但在构建的数组中,它被转换为一个int并变成“15”。事实上 print percentile, int(percentile)将显示 “16.0,15”。
如果有人可以帮助我了解为什么这个SciPy的的功能需要一个浮动,然后扔在一个int,为什么INT(16.0)给出了15,我在这里。

PS:即使numpy.array(generif_filter(...), dtype=numpy.float),我得到的整数的错误的表。

回答

0

哇,该溶液是棘手的。 Scipy会将所返回的表格的所有值转换为第一个表格的类型。
对于为例:

table = [0,1,2,3,4,5,6,7,8,9] 
generic_filter(table, ...) # returns a table of integers 
table = numpy.array(table, numpy.float) 
generic_filter(table, ...) # returns this time a table of floats 

所以,如果像我一样没有道理SciPy的蒙上他的输出,改变你的输入;)

相关问题