TensorFlow: argmax (min)

Je viens de remarquer un inattendu (au moins pour moi) le comportement dans TensorFlow. J'ai pensé tf.argmax (-argmin) fonctionne sur le rang du Tenseur de l'extérieur vers l'intérieur, mais apparemment il ne fonctionne pas?!

Exemple:

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()
> 2
tf.shape(arr).eval()
> array([6, 6], dtype=int32)

tf.argmax prend deux arguments: input et dimension. Puisque les indices de tableau arr sont arr[rows, columns], je m'attends à ce tf.argmax(arr, 0) pour revenir à l'index de l'élément maximum par ligne, alors que je me serais attendu à tf.argmax(arr, 1) pour retourner l'élément maximum par colonne. De même pour tf.argmin.

Cependant, l'inverse est vrai:

tf.argmax(arr, 0).eval()
> array([0, 3, 2, 4, 0, 1])

# 0 -> 31 (arr[0, 0])
# 3 -> 30 (arr[3, 1])
# 2 -> 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()
> array([5, 5, 2, 1, 3, 0])

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

Quelqu'un peut expliquer ce comportement?

Généralisée de tous les n-dimensions du Tenseur de t est indexé par t[i, j, k, ...]. Ainsi, t a rang n et la forme (i, j, k, ...). Depuis de dimension 0 correspond à i, de dimension 1 de j, et ainsi de suite. Pourquoi ne tf.argmax (& -argmin) ignorer ce dispositif?

OriginalL'auteur daniel451 | 2016-06-29