tensorflow - 如何找到 Tensorflow 最大值索引,但该值是重复的

标签 tensorflow

一个张量数组是: 数组 = [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/

相关文章:

python-3.x - Tensorflow 错误 "UnimplementedError: Cast string to float is not supported"- 使用估计器的线性分类器模型

python - 使用 numpy 方法修改(keras/tensorflow)张量

python - Keras自定义损失函数访问python全局变量时的内部机制是什么?

loops - Keras Tensorflow 完全重置

python - mobilenetv2 tflite 不是 python3 的预期输出大小

python - 分类交叉熵和二元交叉熵之间的区别

c++ - 无法读取已保存的TensorFlow模型(无法查找标题条目)

python - model.save 收到 Not JSON Serialized 错误。 tensorflow 1.14.0

python - 对不同的错误分类进行不同的权重 keras

python - 保存使用 keras 训练的 TF 模型,然后在 Go 中进行评估