统计信息中的FutureWarning

时间:2019-10-01 19:23:29

标签: python numpy scipy

我要发挥的作用是计算每个bin的径向平均和重拨中位数,并测试一张* .tif格式的图像。

import numpy as np
from math import fabs
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from PIL import Image
from scipy import stats


def av_radial_profile(data, center):
    y, x = np.indices((data.shape))
    r = np.hypot(x - center[0],y - center[1])
    r = r.astype(np.int)
    b = len(set(r.ravel()))
    av_radialprofile = stats.binned_statistic(r.ravel(), data.ravel(), statistic ='mean', bins = b)[0]

    median_radialprofile = stats.binned_statistic(r.ravel(), data.ravel(), statistic = lambda q: np.nanmedian(q), bins = b)[0]  

    return median_radialprofile, av_radialprofile


img = mpimg.imread('test.tif',0)
center, radi = (509, 546), 55
rad2, rad3 = av_radial_profile(img, center)

图片在这里the tif-format picture 运行此代码后,我面临以下警告消息:

~miniconda3/lib/python3.7/site-packages/scipy/stats/_binned_statistic.py:607: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  result = result[core]

我尝试搜索问题的原因,发现原因可能基于旧软件包版本。因此,在此之后,我用conda更新了所有软件包,然后再次运行我的代码,但警告消息并未消失。

也许是,有人遇到了同样的问题。非常感谢您提供有关代码的帮助和注释。

1 个答案:

答案 0 :(得分:1)

在scipy 1.3.1中,“违规”代码现在为

# Remove outliers (indices 0 and -1 for each bin-dimension).
core = tuple([slice(None)] + Ndim * [slice(1, -1)])
result = result[core]

scipy/stats/_binned_statistic.py文件中。