k_mean.fit returns ValueError: setting an array element with a sequence

k_mean.fit returns ValueError: setting an array element with a sequence

我正在尝试通过已保存为数组列表的图像特征表示,通过 kmeans 进行聚类。

features_list = []
features = np.asarray(features_list)  

features_flat = features.reshape((features.shape[0], -1))
k_means = cluster.KMeans(n_clusters=10, n_jobs=-1)
k_means.fit(features_flat)

features_flat 的信息如下:

print(features_flat)

Out:[[ array([[[ 0.36470588,  0.32156863,  0.2627451 ,  0.36862745],
    [ 0.36470588,  0.32156863,  0.2627451 ,  0.36862745],
    [ 0.36470588,  0.32156863,  0.2627451 ,  0.36862745],
    ..., 
[ array([[[ 0.19607843,  0.19215686,  0.14117647,  0.30980392],
    [ 0.19607843,  0.19215686,  0.14117647,  0.30980392],
    [ 0.19607843,  0.19215686,  0.14117647,  0.30980392],
    ..., 
    ]]

np.unique(list(map(len, features_flat)))
Out: array([1])

当 运行 k_means.fit()

时出现以下错误
ValueError: setting an array element with a sequence.

如何在创建正确类型的矩阵时保留数组中的数据?

感谢@lejlot

它适用于此转换的图像表示。

Standardized image size for each image + mapped to grayscale

我希望它能与下面的图像表示一起使用

Original image transformation

,但这解决了这个特定问题。