我正在寻找一种类似于Python的list.index()函数的TensorFlow方法。如何查找TensorFlow中第一个匹配元素的索引
给出一个矩阵和一个值来查找,我想知道在矩阵的每一行中值的第一次出现。
例如,
m is a <batch_size, 100> matrix of integers
val = 23
result = [0] * batch_size
for i, row_elems in enumerate(m):
result[i] = row_elems.index(val)
我不能假设“VAL”只出现在每行中一次,否则我会使用tf.argmax(米== VAL)已经实现它。在我的情况下,重要的是要获得第一个发生'val'的索引,而不是任何。
这非常有帮助!如果我们想将val更新为new_val,该怎么办?我在这里问这个问题:https://stackoverflow.com/questions/45684445/tensorflow-update-first-matching-element-in-each-row – reese0106