Last active
January 16, 2021 03:39
-
-
Save mihkell/49eb7d3d802ba28834b6446c6ddc834f to your computer and use it in GitHub Desktop.
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
import numpy as np | |
import tensorflow as tf | |
input_tensor = tf.constant(1, dtype=tf.int64) | |
keys = tf.constant(np.array([1,2,3]), dtype=tf.int64) | |
values = tf.constant(np.array([4,5,6]), dtype=tf.int64) | |
default_value = tf.constant(-1, dtype=tf.int64) | |
table = tf.contrib.lookup.HashTable( | |
tf.contrib.lookup.KeyValueTensorInitializer(keys, values), default_value) | |
out = table.lookup(input_tensor) | |
with tf.Session() as sess: | |
table.init.run() | |
print(out.eval()) # 4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment