Last active
August 3, 2017 08:18
-
-
Save yaroslavvb/432de370d9d0f3878ea754af39134b50 to your computer and use it in GitHub Desktop.
Example of dynamic stitch to add vector to first row of matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = tf.constant([[1,2],[3,4]]) | |
row_to_add = tf.constant([1, 1]) | |
original_row = a[0] | |
updated_row = original_row + row_to_add | |
unchanged_indices = tf.range(tf.size(a)) | |
changed_indices = tf.range(a.get_shape()[0]) | |
a_flat = tf.reshape(a, [-1]) | |
updated_a_flat = tf.dynamic_stitch([unchanged_indices, changed_indices], [a_flat, updated_row]) | |
updated_a = tf.reshape(updated_a_flat, a.get_shape()) | |
print sess.run(updated_a) | |
# [[2 3] | |
# [3 4]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment