【发布时间】:2017-05-12 22:14:24
【问题描述】:
附上代码:
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 需要返回一个浮点数和“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),我也得到了错误的整数表。
【问题讨论】:
标签: python python-2.7 numpy casting scipy