上面是正常的 只要元素同個大小的就不會有問題
print(array)
[[0.104 0.923 0.105 0.108]
[0.107 0.253 0.107 0.251]]
kmeans_fit = cluster.KMeans(n_clusters = 2).fit(array)
cluster_labels = kmeans_fit.labels_
ppt=kmeans_fit.labels_
print(ppt)
[0 1]
只要元素數量有不同就會出現ValueError: setting an array element with a sequence.
[list([0.107, 0.111, 0.11, 0.108]) list([0.107, 0.115, 0.113, 0.109])
list([0.104, 0.923, 0.105, 0.108]) list([0.11, 0.112, 0.107, 0.108])
list([0.107, 0.253, 0.107, 0.251]) list([0.106, 0.128])]
[[0.107, 0.111, 0.11, 0.108], [0.107, 0.115, 0.113, 0.109], [0.104, 0.923, 0.105, 0.108], [0.11, 0.112, 0.107, 0.108], [0.107, 0.253, 0.107, 0.251], [0.106, 0.128]]
ValueError: setting an array element with a sequence.
我原本是使用list 上網查很多人轉成array就可以,但無法解決 有人遇過然後解決的嗎?