tf.argmax() in tensorflow

tf.argmax is to return the index value of the largest value. tf.argmax is np.argmax>

There is a difference between tf.argmax(array, 1) and tf.argmax(array, 0) (axis is 1 and 0 respectively).

example:

test = np.array([[1, 2, 3], [2, 3, 4], [5, 4, 3], [8, 7, 2]])
np.argmax(test, 0) # output: array([3, 3, 1]
np.argmax(test, 1) # output: array([2, 2, 0, 0]

explain:

tf.argmax(array, 0) is to compare numbers at the same position in different arrays. For example, the following is to compare the numbers in each column and return the index of the largest value in each column of numbers.

When the lengths of the arrays are inconsistent, axis=0, which becomes a comparison of the sum of each array.

test[0] = array([1, 2, 3])
test[1] = array([2, 3, 4])
test[2] = array([5, 4, 3])
test[3] = array([8, 7, 2])
# output   :    [3, 3, 1]    
tf.argmax(array, 0) is to compare numbers in the same array. For example, the following is to compare each row of numbers and return the index of the largest value in each row of numbers.
test[0] = array([1, 2, 3])  #2
test[1] = array([2, 3, 4])  #2
test[2] = array([5, 4, 3])  #0
test[3] = array([8, 7, 2])  #0


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326710209&siteId=291194637