在数组数组中查找np.array的索引

时间:2019-11-14 22:03:11

标签: python arrays numpy

所以我有以下代码

 data = read_coords("breeds.csv")
 data = np.asarray(data)
 kmeans(data, 2)

 def kmeans(dataset, k):
    #this is a numpy array of the form [[x1,y1],[x2,y2]]
    centroids = initialise_centroids(dataset, k)
    #define clusters
    clusters = {}
    for cent in centroids:
        clusters[np.array2string(cent)] = []

    #For each item in the set
    for item in dataset:
        #Find which centroid is nearest
        closest = find_nearest_centroid(centroids, item)
        #Assign to cluster
        key = np.array2string(closest)
        temp = clusters.get(key)
        temp.append(item)

    return centroids, clusters

我想编写一个函数,通过键迭代字典,然后在值列表中找到特定点的地方将其删除。我什至找不到它?

def isInCluster(point, clusters):
    for key in clusters:
        if point in clusters[key]...

我对使用np.where()感到厌倦,但似乎什么也没返回。在当前状态下,我得到ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

0 个答案:

没有答案