python - scipy stats 中的 FutureWarning
问题描述
我创建了一个函数,其作用是计算每个 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)
~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 更新了所有的包并再次重新运行我的代码,但是警告信息并没有消失。
可能有人遇到了同样的问题。我将非常感谢有关我的代码的任何帮助和说明。
解决方案
在 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
文件中。
推荐阅读
- php - 将货币选择器添加到 laravel
- reactjs - 在地图功能中渲染状态并添加一些样式反应js
- typescript - 为 TypeScript 使用 @Prop 装饰器 - 编译器在要求初始化 prop 时出错
- sql - 如何使用 count(*) group by 的结果选择值?
- javascript - TypeError:解构对象后“x”是(不是)“y”
- php - Php mailer 给我一个成功的消息,但没有传递消息
- azure - 如何将网关子网添加到包含 Azure 上的 VM 的 Vnet
- sql - compare rows between two ids with in the same table and insert the missing row for that id
- regex - Rewrite except loading JS files
- node.js - error while installing "npm install -g ionic cordova"