Reputation: 31
A tensor array is: array = [1, 1, 0, 1, 1, 0]
If I use tf.argmax(), its can find only the first index. output => "0"
But I want find the max value at last index. output would be "4"
Upvotes: 3
Views: 1085
Reputation: 222521
tf.argmax does not return the first maximum. In case of tie anything can be returned:
Note that in case of ties the identity of the return value is not guaranteed.
So the answers like reverse and argmax are wrong.
One option which I can see is:
import tensorflow as tf
a = tf.constant([5, 3, 3, 5, 4, 2, 5, 1])
b = tf.argmax(tf.multiply(
tf.cast(tf.equal(a, tf.reduce_max(a)), tf.int32),
tf.range(1, a.get_shape()[0] + 1)
))
with tf.Session() as sess:
print sess.run(b)
If your starting vector is does not consist of integers, you need to change the type.
Upvotes: 5