ValueError:形状不匹配

时间:2018-09-30 11:25:11

标签: python numpy k-means

我正在尝试K-均值图像压缩,但出现此错误

Command PrecompileSwiftBridgingHeader failed with a nonzero exit code

我的代码:

File "C:/Users/[user]/PycharmProjects/project/CompressMe.py", Line23, in <module>
    final[pixel_centroids == cluster_no] = cluster_centers[cluster_no]
ValueError: shape mismatch: value array of shape (4,) could not be broadcast to indexing result of shape (267049,3)

1 个答案:

答案 0 :(得分:0)

初始化“ final”数组时,将png输出通道的数量硬编码为3,这可能与输入不同。更正以下几行:

final = np.zeros((pixel_centroids.shape[0], img_np.shape[2]))

comp_image = final.reshape(img_np.shape[0], img_np.shape[1], img_np.shape[2])

相关问题