【发布时间】:2017-10-25 07:01:39
【问题描述】:
我只想从 skimage.exposure 中绘制 Matplotlib 直方图,但我得到了 ValueError: bins must increase monotonically. 原始图像来自 here,这里是我的代码:
from skimage import io, exposure
import matplotlib.pyplot as plt
img = io.imread('img/coins_black_small.jpg', as_grey=True)
hist,bins=exposure.histogram(img)
plt.hist(bins,hist)
ValueError: bins 必须单调增加。
但是当我对 bin 值进行排序时会出现同样的错误:
import numpy as np
sorted_bins = np.sort(bins)
plt.hist(sorted_bins,hist)
ValueError: bins 必须单调增加。
我终于尝试检查 bin 值,但在我看来它们似乎已排序(对于此类测试的任何建议也将不胜感激):
if any(bins[:-1] >= bins[1:]):
print "bim"
没有输出。
有什么建议吗?
我正在努力学习 Python,所以请放纵一下。这是我的安装(在 Linux Mint 上):
- Python 2.7.13 :: Anaconda 4.3.1(64 位)
- Jupyter 4.2.1
【问题讨论】:
-
当数组中有 NaN 时,我经常看到这种情况。
any(np.isnan(img))返回什么? -
@bnaecker > ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()
标签: python matplotlib scikit-image