我是Tensorflow的新手。你知道吗
我有一个问题。你知道吗
这里有1d阵列。你知道吗
values = [101,103,105,109,107]
target_values = [105, 103]
我想马上从values
得到一个关于target_values
的索引。你知道吗
下面将显示从上述示例中提取的索引。你知道吗
indices = [2, 1]
当我使用tf.map_fn
函数时。
这个问题很容易解决。你知道吗
# if you do not change data type from int64 to int32. TypeError will riase
values = tf.cast(tf.constant([100, 101, 102, 103, 104]), tf.int64)
target_values = tf.cast(tf.constant([100, 101]), tf.int64)
indices = tf.map_fn(lambda x: tf.where(tf.equal(values, x)), target_values)
谢谢你!你知道吗
假设
target_values
中的所有值都在values
中,这是一种简单的方法(tf2.x,但函数对1.x的作用应该相同):相关问题 更多 >
编程相关推荐