一个张量数组是: 数组 = [1, 1, 0, 1, 1, 0]
如果我使用 tf.argmax(),它只能找到第一个索引。 输出=>“0”
但我想在最后一个索引处找到最大值。 输出将是“4”
最佳答案
tf.argmax不返回第一个最大值。如果领带任何东西都可以退回:
Note that in case of ties the identity of the return value is not guaranteed.
所以 reverse 和 argmax 这样的答案是错误的。
我可以看到的一个选项是:
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)
如果您的起始向量不是整数,则需要更改类型。
关于tensorflow - 如何找到 Tensorflow 最大值索引,但该值是重复的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45115650/