2016-03-07 17 views
8

TensorFlow'da indekslemenin nasıl yapılacağı hakkında temel bir sorum var. Numpy olarakTensorFlow: başka bir tensörü indekslemek için bir tensör kullanarak

:

x = np.asarray([1,2,3,3,2,5,6,7,1,3]) 
e = np.asarray([0,1,0,1,1,1,0,1]) 
#numpy 
print x * e[x] 

Ben TensorFlow içinde

[1 0 3 3 0 5 0 7 1 3] 

Bunu nasıl yapabilirim alabilirim?

x = np.asarray([1,2,3,3,2,5,6,7,1,3]) 
e = np.asarray([0,1,0,1,1,1,0,1]) 
x_t = tf.constant(x) 
e_t = tf.constant(e) 
with tf.Session(): 
    ???? 

Teşekkürler! Neyse

+0

http://stackoverflow.com/questions/33736795/tensorflow-numpy-like-tensor-indexing?rq=1 Sormak istediğin şey bu değil mi? – Alleo

cevap

19

, sen tf.gather() tarafından TensorFlow desteklenir soruyorsun tam durum:

result = x_t * tf.gather(e_t, x_t) 

with tf.Session() as sess: 
    print sess.run(result) # ==> 'array([1, 0, 3, 3, 0, 5, 0, 7, 1, 3])' 

tf.gather() op NumPy's advanced indexing daha az güçlüdür: sadece kendi 0 boyutuyla ilgili bir tensör dolu dilimleri ayıklanması destekler . Daha genel endeksleme desteği talep edildi ve this GitHub issue numaralı telefondan takip ediliyor.

+1

Çok teşekkür ederim! – user200340

+3

Tensorflow artık daha güçlü bir 'tf.gather_nd() 'op. – fritzo

İlgili konular