统计numpy数组中每个值出现的个数

统计numpy数组中某一个值或某几个值出现的个数:sum(data==4)

# 统计出现了几个cluster
    include0Cluster = sum(res == 0)
    include1Cluster = sum(res == 1)
    include2Cluster = sum(res == 2)
    include3Cluster = sum(res == 3)
    include4Cluster = sum(res == 4)
    include5Cluster = sum(res == 5)
    include6Cluster = sum(res == 6)
    include7Cluster = sum(res == 7)
    include8Cluster = sum(res == 8)
    include9Cluster = sum(res == 9)
    include10Cluster = sum(res == 10)
    print(include0Cluster, include1Cluster, include2Cluster, include3Cluster, include4Cluster, include5Cluster,
          include6Cluster, include7Cluster, include8Cluster, include9Cluster, include10Cluster)

 

转载于:https://www.cnblogs.com/shenxiaolin/p/11101858.html

你可能感兴趣的:(统计numpy数组中每个值出现的个数)