python中的ay数组没有得到更新

时间:2015-03-21 05:00:59

标签: python list dictionary ordereddictionary

以下是从另一个模块首先调用调用者的代码, 质心是浮点型(numberofcluster * numberoffeatures的数组) 标签是1d数组的数组

数组没有得到更新

def caller(centroids, labels):

    number_of_features = len(centroids[0])
    one_column = [0, 0, 0, 0, 0]

    i = 0
    j = 0

    array = [[0 for x in xrange(number_of_features)] for x in xrange(5)]

    while i < number_of_features:
        j = 0
        while j < 5:
            one_column[j] = centroids[j][i]
            j += 1

        rank(one_column, i, array)
        i += 1 


    return calculatemean(number_of_features, array)


def rank(one_column, ithfeature, array):

    temp_dict = {}
    i = 0
    while i < 5:
         temp_dict[one_column[i]] = i
         i += 1

    number_of_uniquevalues = len(set(temp_dict))
    sorted_dict = OrderedDict(sorted(temp_dict.items()))

    i = 0
    keys_list = sorted_dict.keys()

    while i < 5:
        array[one_column.index(keys_list[i])][ithfeature] = sorted_dict[keys_list[i]]
        i += 1

1 个答案:

答案 0 :(得分:0)

我已经提到了这个链接

Two dimensional array in python

问题已解决