Python scipy generic_筛选器强制转换返回值

Python scipy generic_筛选器强制转换返回值,python,python-2.7,numpy,casting,scipy,Python,Python 2.7,Numpy,Casting,Scipy,使用代码: def stat_function(x): center = x[len(x) / 2] ecdf = ECDF(xx) percentile = (1 - ecdf(center)) * 100 print percentile return percentile 主要内容: 我得到了输出: [[84 76 76 76 76 76 76 76 76 60] [52 48 48 48 48 48 48 48 48 39] [52 48 48

使用代码:

def stat_function(x):
    center = x[len(x) / 2]
    ecdf = ECDF(xx)
    percentile = (1 - ecdf(center)) * 100
    print percentile
    return percentile
主要内容: 我得到了输出:

[[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]]
一切正常,但如果我在返回之前在函数中打印“percentile”,我会发现我所有的15实际上都是16.0,我的39都是40.0。函数generic_filter要求返回一个float,返回“16.0”,但在构建的数组中,它被转换为int并变成“15”。确实如此
打印百分位数,int(百分位数)
将显示“16.0,15”。
如果有人能帮助我理解为什么这个scipy函数需要一个浮点,然后把它转换成int,为什么int(16.0)给出15,我就在这里


PS:即使使用
numpy.array(generif\u filter(…),dtype=numpy.float)
,我也得到了错误的整数表。

哇,解决方案很棘手。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无理由强制转换其输出,请更改您的输入;)

哇,解决方案很棘手。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无缘无故地播放他的输出,请更改您的输入;)