2017-03-03 1 views
2
tf_coo = tf.SparseTensor(indices=np.array([[0, 0, 0, 1, 1, 2, 3, 9], 
              [1, 4, 9, 9, 9, 9, 9, 9]]).T, 
         values=[1, 2, 3, 5,1,1,1,1], 
         shape=[10, 10]) 

Ich erhalte die Fehlermeldunginitialisieren Tensoren

InvalidArgumentError (see above for traceback): indices[4] = [1,9] is repeated 
    [[Node: SparseToDense = SparseToDense[T=DT_INT32, Tindices=DT_INT64, validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](SparseTensor/indices, SparseToDense/output_shape, SparseTensor/values, SparseToDense/default_value)]] 

Ist es nicht möglich, jus konstruieren zwei Listen von Indizes und Werte zu ihnen? Ich habe vorher coo_matrix benutzt und es löst das sehr gut. Irgendeine Hilfe?

EDIT: Ich löste es durch Erstellen einer CSR_Matrix, dass ich die Funktion sort_indices() verwendet, dann habe ich es in Coo_matrix umgewandelt. Ich schaffe Von dort gerade eine SparseTensor

tf.SparseTensor(indices= (coo_martix.row, coo_martix.col), values= coo_matrix.data, dense_shape=coo_martix.shape) 
+0

Sie sollten Ihre Lösung als Antwort setzen. – daknowles

Antwort

0

einfach die doppelte [1,9] in indices entfernen:

from __future__ import print_function 
import tensorflow as tf 
import numpy as np 
tf_coo = tf.SparseTensor(indices=np.array([[0, 0, 0, 1, 2, 3, 9], 
              [1, 4, 9, 9, 9, 9, 9]]).T, 
         values=[1, 2, 3, 1,1,1,1], 
         dense_shape=[10, 10]) 

print('tf_coo: {0}'.format(tf_coo)) 
print('tf_coo.get_shape(): {0}'.format(tf_coo.get_shape())) 
+0

Ja, aber die Daten, die ich erhalten habe, enthalten doubles und mit coo_matrix fügen Sie einfach die neuen Indizes zum bestehenden Element hinzu. Also, wenn zuerst [1,9] = 4 und Sekunde [1,9] = 1, zeigt die Matrix 5. –

+0

@MarcusLagerstedt Ich sehe. Ich denke SparseTensor verhält sich anders. –

+0

Ich habe die Fehlermeldung wie "AttributeError: Typ Objekt 'Coo_matrix' hat kein Attribut 'Zeilen'" – mgokhanbakal

Verwandte Themen