私はPythonには新しく、相関が最も高い10個のアイテムを(10 x 3)マトリックスに格納しようとしています。最後の行の値(最小値)を指定し、より高い値の値が挿入されている場合は行の順序を変更します。私の問題は、値を読み取り、変更するためにposition(i、j)内の特定のアイテムにアクセスする方法を理解できないことです。ここでは、私のコードです:構造化配列Pythonの中で最も関連性の高いアイテムを10個保存する
dtype = [('tag1', 'S8'), ('tag2', 'S8'), ('correlation', 'f8')]
most_related_tags = np.zeros((10,3),dtype=dtype)
for i in tags:
for j in tags:
if(i['tag'] != j['tag']):
correlation = tagCorrelation(tagsFile,str(i['tag']),str(j['tag']))
if(correlation > 0):
print most_related_tags[9,2]
if(most_related_tags[9,2] < correlation):
print "entered"
most_related_tags[9,2] = correlation;
most_related_tags[9,0] = str(i['tag']);
most_related_tags[9,1] = str(j['tag']);
most_related_tags = np.sort(most_related_tags,order='correlation')
問題がmost_related_tags [9,2] most_related_tags.item(9,2)どちらが正しいオブジェクトを返すため
はい、3つのフィールドを含む項目の配列が必要でした。大いに感謝する –