def get_sd_labels(centroid_indices, items, dist_func, distance_matrix=None):
    """Compute the assigned cluster label for each item given the indices of the approximate centroids"""
    labels = []
    for item_index in range(len(items)):
        min_distance = float('inf')
        label = -1
        for index in range(len(centroid_indices)):
            if distance_matrix is None:
                dist = dist_func(items[centroid_indices[index]], items[
                    item_index])
            else:
                dist = distance_matrix[centroid_indices[index], item_index]
            if dist < min_distance:
                min_distance = dist
                label = index
        labels.append(label)
    return labels
