How to find an index of the first matching element in TensorFlow : <p>I am looking for a TensorFlow way of implementing something similar to Python's list.index() function.</p>

<p>Given a matrix and a value to find, I want to know the first occurrence of the value in each row of the matrix.</p>

<p>For example,</p>

<pre><code>m is a &lt;batch_size, 100&gt; matrix of integers
val = 23

result = [0] * batch_size
for i, row_elems in enumerate(m):
  result[i] = row_elems.index(val)
</code></pre>

<p>I cannot assume that 'val' appears only once in each row, otherwise I would have implemented it using tf.argmax(m == val). In my case, it is important to get the index of the <em>first</em> occurrence of 'val' and not any.</p>
