Last active
February 28, 2023 18:13
-
-
Save rahulremanan/12ba7f20433071b8d28a6f7275d727e7 to your computer and use it in GitHub Desktop.
Using Tensorflow while_loop to manipulate the named tuples
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
Pair = collections.namedtuple('Pair', 'j, k') | |
ijk_0 = (tf.constant(0), Pair(tf.constant(1), tf.constant(2))) | |
c = lambda i, p: i < 10 | |
b = lambda i, p: (i + 1, Pair((p.j + p.k), (p.j - p.k))) | |
ijk_final = tf.while_loop(c, b, ijk_0) | |
print(ijk_final[-1].j.numpy(), ijk_final[-1].k.numpy()) | |
print(ijk_final[-1][0].numpy(), ijk_final[-1][1].numpy()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment