label = vq(data, code)[0]
// Update the code by computing centroids using the new code book
for j in range(nc):
mbs = np.where(label == j)
if mbs[0].size > 0:
code[j] = np.mean(data[mbs], axis=0)
else:
missing()
After Change
label = vq(data, code)[0]
// Update the code by computing centroids using the new code book
new_code, has_members = _vq.update(data, label, nc)
if not has_members.all():
missing()
// Set the empty clusters to their previous positions
new_code[~has_members] = code[~has_members]