Ich habe zwei Wörterbücher erstellt, die Histogrammwerte von Bildern enthalten. Jedes Wörterbuch hat den Dateinamen der Bilddatei als Schlüssel und die Liste der drei eindimensionalen Vektoren, die zusammengefügt wurden, als seine Werte.
例 {'someFileName.jpg' : ['forecolor=2,3,5,5,6','edge=2,4,5','texture=5,4,3']}
Hier ist eine aktuelle Darstellung eines meiner Wörterbücher:
Wörterbuch1
{'/Users/images/Transcend-8GB-Class-10-SDHC-Flash-Memory-Card.jpg': ['fcolor=2,4,14,5,0,0,0,0,0,0,0,0,0,0,12,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,6,0,0,0,0,1,0,0,0,0,0,0,0,0,0,20,9,0,0,0,2,2,0,0,0,0,0,0,0,0,0,13,6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,10,8,0,0,0,1,2,0,0,0,0,0,0,0,0,0,17,17,0,0,0,3,6,0,0,0,0,0,0,0,0,0,7,5,0,0,0,2,0,0,0,0,0,0,0,0,0,0,4,3,0,0,0,1,1,0,0,0,0,0,0,0,0,0,6,6,0,0,0,2,3', 'edge=1,252,1,32,124,194,63,252,67,15,240,1,7,244,66,47,0,192,63', 'texture=1,78,27,37,13,6,6,7,78']}
Wörterbuch2
{'/Users/images/kodax-camera-M531.jpg': ['fcolor=2,74,6,20,30,1,2,0,1,0,0,0,1,3,2,0,0,0,0,0,1,1,1,0,0,2,0,0,0,2,2,0,0,0,0,0,2,2,1,0,0,5,0,0,0,1,4,0,0,0,0,0,2,2,1,0,0,1,0,0,0,3,1,0,0,0,0,0,1,1,0,0,0,3,0,0,0,1,2,0,0,0,0,0,2,2,1,0,0,4,0,0,0,0,5,0,0,0,0,0,2,1,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0', 'edge=1,4,1,88,128,22,8,39,25,142,230,226,31,60,64,255,252,12,76', 'texture=1,15,32,31,28,19,16,12,98']}
Mein Endziel ist es, zwei dieser Wörterbücher an eine Methode zu übergeben und tatsächlich cosign Wert ausführen,
Beispiel: So jedes Wörterbuch hat Liste als sein Wert, so für jedes Wörterbuch Schlüssel ich tun möchten Vektor-Multiplikation zwischen dictionary1's key1, velu1 mit dictionary2 key1, value1,
Ich habe die Vektor-Multiplikation-Funktion, so was ich versuche, herauszufinden, wie man richtig iterieren, ich dachte entlang der Linie der Verwendung einer Yield-Funktion, aber es hat nicht wirklich funktionieren, wenn ich versucht. Dies ist, was ich so weit haben:
def cosignSimilarity(image1VectorDict, image2VectorDict):
for image1Key, image2Value in image1VectorDict.iteritems():
print image1Key
for aValue in image1Value:
print aValue
for image2Key, image2Value in image2VectorDict.iteritems():
for eValue in image2Value:
print aValue
print "\n"
print eValue
Zu Ihrer Information: Ich bitte nicht um Hilfe bei der Berechnung der Mitunterschrift.
Dies ist, wie mein aktueller Code die Daten ausspuckt, wenn ich Schlüssel zu Schlüssel von einem Wörterbuch zu einem anderen isolieren kann, dann kann ich den Rest wie die Berechnung von Kosinuswerten tun.
First Dictionary
{'/Users/test/Transcend-8GB-Class-10-SDHC-Flash-Memory-Card.jpg': ['fcolor=2,4,14,5,0,0,0,0,0,0,0,0,0,0,12,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,6,0,0,0,0,1,0,0,0,0,0,0,0,0,0,20,9,0,0,0,2,2,0,0,0,0,0,0,0,0,0,13,6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,10,8,0,0,0,1,2,0,0,0,0,0,0,0,0,0,17,17,0,0,0,3,6,0,0,0,0,0,0,0,0,0,7,5,0,0,0,2,0,0,0,0,0,0,0,0,0,0,4,3,0,0,0,1,1,0,0,0,0,0,0,0,0,0,6,6,0,0,0,2,3', 'edge=1,252,1,32,124,194,63,252,67,15,240,1,7,244,66,47,0,192,63', 'texture=1,78,27,37,13,6,6,7,78']}
------------------
Second Dictionary
{'/Users/test/kodax-camera-M531.jpg': ['fcolor=2,74,6,20,30,1,2,0,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,66,47,0,192,63
fcolor=2,74,6,20,30,1,2,0,1,0,0,0,1,3,2,0,0,0,0,0,1,1,1,0,0,2,0,0,0,2,2,0,0,0,0,0,2,2,1,0,0,5,0,0,0,1,4,0,0,0,0,0,2,2,1,0,0,1,0,0,0,3,1,0,0,0,0,0,1,1,0,0,0,3,0,0,0,1,2,0,0,0,0,0,2,2,1,0,0,4,0,0,0,0,5,0,0,0,0,0,2,1,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0
edge=1,252,1,32,124,194,63,252,67,15,240,1,7,244,66,47,0,192,63
edge=1,4,1,88,128,22,8,39,25,142,230,226,31,60,64,255,252,12,76
edge=1,252,1,32,124,194,63,252,67,15,240,1,7,244,66,47,0,192,63
texture=1,15,32,31,28,19,16,12,98
texture=1,78,27,37,13,6,6,7,78
texture=1,78,27,37,13,6,6,7,78
fcolor=2,74,6,20,30,1,2,0,1,0,0,0,1,3,2,0,0,0,0,0,1,1,1,0,0,2,0,0,0,2,2,0,0,0,0,0,2,2,1,0,0,5,0,0,0,1,4,0,0,0,0,0,2,2,1,0,0,1,0,0,0,3,1,0,0,0,0,0,1,1,0,0,0,3,0,0,0,1,2,0,0,0,0,0,2,2,1,0,0,4,0,0,0,0,5,0,0,0,0,0,2,1,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0
texture=1,78,27,37,13,6,6,7,78
edge=1,4,1,88,128,22,8,39,25,142,230,226,31,60,64,255,252,12,76
texture=1,78,27,37,13,6,6,7,78
texture=1,15,32,31,28,19,16,12,98
Wie Sie sehen können, spucke ich viel zu viele Wiederholungen desselben Wertes aus.
Dies sind die aktuellen Wörterbücher, mit denen ich zu tun habe:
Wörterbuch 1:
{'/Users/test/Transcend-8GB-Class-10-SDHC-Flash-Memory-Card.jpg': ['fcolor=2,4,14,5,0,0,0,0,0,0,0,0,0,0,12,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,6,0,0,0,0,1,0,0,0,0,0,0,0,0,0,20,9,0,0,0,2,2,0,0,0,0,0,0,0,0,0,13,6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,10,8,0,0,0,1,2,0,0,0,0,0,0,0,0,0,17,17,0,0,0,3,6,0,0,0,0,0,0,0,0,0,7,5,0,0,0,2,0,0,0,0,0,0,0,0,0,0,4,3,0,0,0,1,1,0,0,0,0,0,0,0,0,0,6,6,0,0,0,2,3', 'edge=1,252,1,32,124,194,63,252,67,15,240,1,7,244,66,47,0,192,63', 'texture=1,78,27,37,13,6,6,7,78']}
Wörterbuch 2:
{'/Users/test/kodax-camera-M531.jpg': ['fcolor=2,74,6,20,30,1,2,0,1,0,0,0,1,3,2,0,0,0,0,0,1,1,1,0,0,2,0,0,0,2,2,0,0,0,0,0,2,2,1,0,0,5,0,0,0,1,4,0,0,0,0,0,2,2,1,0,0,1,0,0,0,3,1,0,0,0,0,0,1,1,0,0,0,3,0,0,0,1,2,0,0,0,0,0,2,2,1,0,0,4,0,0,0,0,5,0,0,0,0,0,2,1,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0', 'edge=1,4,1,88,128,22,8,39,25,142,230,226,31,60,64,255,252,12,76', 'texture=1,15,32,31,28,19,16,12,98']}
Ich habe die Funktion Lamba
cosinLamba = lambda a, b : round(NP.inner(a, b)/(LA.norm(a)*LA.norm(b)), 3)
Ich möchte über Wörterbuch 1 und Wörterbuch 2 iterieren und den fcolor-Wert von Wörterbuch 1 erhalten 'fcolor=2,4,14,5,0,0,0,0,0,0,0,0,0,0,12,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,6,0,0,0,0,1,0,0,0,0,0,0,0,0,0,20,9,0,0,0,2,2,0,0,0,0,0,0,0,0,0,13,6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,10,8,0,0,0,1,2,0,0,0,0,0,0,0,0,0,17,17,0,0,0,3,6,0,0,0,0,0,0,0,0,0,7,5,0,0,0,2,0,0,0,0,0,0,0,0,0,0,4,3,0,0,0,1,1,0,0,0,0,0,0,0,0,0,6,6,0,0,0,2,3'
und fcolor-Wert von dictionary2
'fcolor=2,74,6,20,30,1,2,0,1,0,0,0,1,3,2,0,0,0,0,0,1,1,1,0,0,2,0,0,0,2,2,0,0,0,0,0,2,2,1,0,0,5,0,0,0,1,4,0,0,0,0,0,2,2,1,0,0,1,0,0,0,3,1,0,0,0,0,0,1,1,0,0,0,3,0,0,0,1,2,0,0,0,0,0,2,2,1,0,0,4,0,0,0,0,5,0,0,0,0,0,2,1,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0'
Schicken Sie sie an meine Lamba-Funktion cosinLamba(valu1, value2)
Wert1 und Wert 2 sind Zeichenketten und deshalb habe ich sie in meinem Wörterbuch als Werte gespeichert. Und ich möchte für fcolor, texture, edge alle Vektoren, die ich für ein bestimmtes Bild in jedem Wörterbuch gespeichert habe, verwenden.