簡體   English   中英

ValueError:無法將輸入數組從形狀(0,2)廣播到形狀(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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM