Based on this question I want to update the values โโof the two-dimensional tensor for the first time in a row when the tf.where condition is met. Here is an example of the code that I use for modeling:
tf.reset_default_graph() graph = tf.Graph() with graph.as_default(): val = "hello" new_val = "goodbye" matrix = tf.constant([["word","hello","hello"], ["word", "other", "hello"], ["hello", "hello","hello"], ["word", "word", "word"] ]) matching_indices = tf.where(tf.equal(matrix, val)) first_matching_idx = tf.segment_min(data = matching_indices[:, 1], segment_ids = matching_indices[:, 0]) sess = tf.InteractiveSession(graph=graph) print(sess.run(first_matching_idx))
This will output [1, 2, 0], where 1 is the placement of the first greeting on line 1, 2 is the placement of the first greeting on line 2, and 0 is the placement of the first greeting on line 3.
However, I canโt understand how to get the first match index, which will be updated with a new value - basically I want the first โhelloโ to be turned into โgoodbyeโ. I tried using tf.scatter_update (), but it doesn't seem to work on 2D tensors. Is there a way to change the two-dimensional tensor as described?
source share