当前位置:  开发笔记 > 编程语言 > 正文

Python 3:图像中最常见的颜色与数据类型匹配

如何解决《Python3:图像中最常见的颜色与数据类型匹配》经验,为你挑选了1个好方法。



1> 小智..:

stacktrace告诉我们唯一支持的数据类型scipy.cluster._vq.update_cluster_means()floatdouble.检查scipy的源代码确认了这一点:

def update_cluster_means(np.ndarray obs, np.ndarray labels, int nc):
    """
    The update-step of K-means. Calculate the mean of observations in each
    cluster.
    Parameters
    ----------
    obs : ndarray
        The observation matrix. Each row is an observation. Its dtype must be
        float32 or float64.
    ...

来源:GitHub上的_vq.pyx

要解决您的问题,首先需要使用numpy.ndarray.astype()将输入转换为支持的数据类型:

codes, dist = scipy.cluster.vq.kmeans(ar.astype(float), NUM_CLUSTERS)
# Or:       = scipy.cluster.vq.kmeans(ar.astype('double'), NUM_CLUSTERS)

推荐阅读
wangtao
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有