[英]Python - ValueError: could not broadcast input array from shape (5) into shape (2)
[英]ValueError: could not broadcast input array from shape (0,2) into shape (2,)
我正在學習 K 方法,但它遇到了一些麻煩。 有人可以幫忙嗎?
def find_new_centroid(X, labels, j):
centers = np.zeros((j, X.shape[1]))
for k in range(j):
# collect all points assigned to the k-th cluster
Xj = X[labels == k, :]
# take average
centers[k, :] = np.mean(Xj, axis=0)
return centers
確保labels
的類型為numpy.ndarray
而不是 Python list
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.