TensorFlow: numpy.repeat() alternative
<p>I want to compare the predicted values <code>yp</code> from my neural network in a pairwise fashion, and so I was using (back in my old numpy implementation):</p>

<pre><code>idx = np.repeat(np.arange(len(yp)), len(yp))
jdx = np.tile(np.arange(len(yp)), len(yp))
s = yp[[idx]] - yp[[jdx]]
</code></pre>

<p>This basically create a indexing mesh which I then use. <code>idx=[0,0,0,1,1,1,...]</code> while <code>jdx=[0,1,2,0,1,2...]</code>. I do not know if there is a simpler manner of doing it...</p>

<p>Anyhow, TensorFlow has a <code>tf.tile()</code>, but it seems to be lacking a <code>tf.repeat()</code>.</p>

<pre><code>idx = np.repeat(np.arange(n), n)
v2 = v[idx]
</code></pre>

<p>And I get the error:</p>

<pre><code>TypeError: Bad slice index [  0   0   0 ..., 215 215 215] of type &lt;type 'numpy.ndarray'&gt;
</code></pre>

<p>It also does not work to use a TensorFlow constant for the indexing:</p>

<pre><code>idx = tf.constant(np.repeat(np.arange(n), n))
v2 = v[idx]
</code></pre>

<p>-</p>

<pre><code>TypeError: Bad slice index Tensor("Const:0", shape=TensorShape([Dimension(46656)]), dtype=int64) of type &lt;class 'tensorflow.python.framework.ops.Tensor'&gt;
</code></pre>

<p>The idea is to convert my <a href="http://research.microsoft.com/en-us/um/people/cburges/papers/ICML_ranking.pdf" rel="noreferrer">RankNet</a> implementation to TensorFlow.</p>