Is there a built-in function in Tensorflow for shuffling or permutating tensors?
<p>What's the best way to permutate a tensor along both axis (first rows and then columns or vice versa)? Should I define a <code>py_func</code> and do it using numpy or use one of tensor transformation functions like <code>tf.slice</code> - I don't know if that's possible.</p>

<p>To achieve this using numpy, I usually do the following:</p>

<pre><code>&gt;&gt;&gt; arr = np.arange(9).reshape([3,3])
&gt;&gt;&gt; arr
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])
&gt;&gt;&gt; col_perm = np.random.permutation(arr.shape[1])
&gt;&gt;&gt; col_perm
array([2, 1, 0])
&gt;&gt;&gt; row_perm = np.random.permutation(arr.shape[0])
&gt;&gt;&gt; row_perm
array([2, 0, 1])
&gt;&gt;&gt; shuffled_arr = arr[row_perm,:][:,col_perm]
&gt;&gt;&gt; shuffled_arr
array([[8, 7, 6],
       [2, 1, 0],
       [5, 4, 3]])
</code></pre>

<p>What about <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/constant_op.html#random_shuffle" rel="nofollow"><code>tf.random_shuffle()</code></a> combined with <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/array_ops.html#transpose" rel="nofollow">tensor transposition</a> (<code>tf.transpose()</code>)?</p>

python numpy tensorflow