TensorFlow: argmax (-min)
<p>I just noticed an unexpected (at least for me) behavior in TensorFlow. I thought <code>tf.argmax</code> (-<code>argmin</code>) operates on the ranks of a Tensor from outer to inner, but apparently it does not?!</p>

<p>Example:</p>

<pre><code>import numpy as np
import tensorflow as tf

sess = tf.InteractiveSession()

arr = np.array([[31, 23,  4, 24, 27, 34],
                [18,  3, 25,  0,  6, 35],
                [28, 14, 33, 22, 20,  8],
                [13, 30, 21, 19,  7,  9],
                [16,  1, 26, 32,  2, 29],
                [17, 12,  5, 11, 10, 15]])

# arr has rank 2 and shape (6, 6)
tf.rank(arr).eval()
&gt; 2
tf.shape(arr).eval()
&gt; array([6, 6], dtype=int32)
</code></pre>

<p><code>tf.argmax</code> takes two arguments: <code>input</code> and <code>dimension</code>. Since the indices of array <code>arr</code> are <code>arr[rows, columns]</code>, I would expect <code>tf.argmax(arr, 0)</code> to return the index of the maximum element per row, while I would have expected <code>tf.argmax(arr, 1)</code> to return the maximum element per column. Likewise for <code>tf.argmin</code>.</p>

<p>However, the opposite is true:</p>

<pre><code>tf.argmax(arr, 0).eval()
&gt; array([0, 3, 2, 4, 0, 1])

# 0 -&gt; 31 (arr[0, 0])
# 3 -&gt; 30 (arr[3, 1])
# 2 -&gt; 33 (arr[2, 2])
# ...
# thus, this is clearly searching for the maximum element
# for every column, and *not* for every row

tf.argmax(arr, 1).eval()
&gt; array([5, 5, 2, 1, 3, 0])

# 5 -&gt; 34 (arr[0, 5])
# 5 -&gt; 35 (arr[1, 5])
# 2 -&gt; 33 (arr[2, 2])
# ...
# this clearly returns the maximum element per row,
# albeit 'dimension' was set to 1
</code></pre>

<p>Can someone explain this behavior?</p>

<p>Generalized every n-dimensional Tensor <code>t</code> is indexed by <code>t[i, j, k, ...]</code>. Thus, <code>t</code> has rank n and shape <code>(i, j, k, ...)</code>. Since dimension 0 corresponds to <code>i</code>, dimension 1 to <code>j</code>, and so forth. Why does <code>tf.argmax</code> (&amp; -<code>argmin</code>) ignore this scheme?</p>