【问题标题】:ValueError: could not broadcast input array from shape (0,2) into shape (2,)ValueError:无法将输入数组从形状(0,2)广播到形状(2,)
【发布时间】:2021-08-24 04:59:11
【问题描述】:

我正在学习 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  

【问题讨论】:

    标签: python k-means


    【解决方案1】:

    确保 labels 的类型为 numpy.ndarray 而不是 Python list

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-30
      • 2018-06-08
      • 2020-01-21
      • 2020-10-18
      • 2018-09-25
      • 2018-04-21
      • 2020-10-09
      • 2021-03-30
      相关资源
      最近更新 更多