Skip to content

Instantly share code, notes, and snippets.

@mihkell
Last active January 16, 2021 03:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihkell/49eb7d3d802ba28834b6446c6ddc834f to your computer and use it in GitHub Desktop.
Save mihkell/49eb7d3d802ba28834b6446c6ddc834f to your computer and use it in GitHub Desktop.
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