1
Ich möchte einen Ausgangstensor erhalten, indem ich index
auf Teilsensoren eines Eingangstensors anwende.Indizierung von Teilsensoren in TensorFlow
Zum Beispiel in NumPy,
import numpy as np
input = np.random.random((100,5)) # matrix
index = np.randint(5, size=(100,)) # vector
output = data[np.arange(index.shape[0]), index] # vector
gibt mir gewünschte Ausgabe (Ich mag symbolische Version dieses).
Similiarly in Theano,
import theano.tensor as T
import theano
input = T.matrix() # symbolic matrix
index = T.ivector() # symbolic vector
output = input[T.arange(index.shape[0]), index] # symbolic vector
gibt mir eine gewünschte output
.
Wie kann ich dies tun in TensorFlow?
import tensorflow as tf
input = tf.placeholder('float32', [None, 5])
index = tf.placeholder('int32', [None])
output = ???
Im Gegensatz zum Beispiel mit NumPy, die Länge von index
(= 1. Dimension der input
) nicht festgelegt ist.
Ich fürchte, das gibt mir falsches Ergebnis:
codebomb
Was ich will: [Eingabe [0] [Index [0]], Eingabe [1] [Index [1]], Eingabe [2] [Index [2]], ...] Was tf. sammeln gibt: [input [index [0]], input [index [1]], ...] – codebomb
@codebomb Okay, sorry, ich missverstanden! Ich habe es jetzt bearbeitet. – jdehesa