【发布时间】:2021-05-10 16:34:33
【问题描述】:
我有一个布尔张量,我想转换为一个和零的二进制张量。
把它放到上下文中 - 我有以下张量
[[ True False True]
[False True False]
[ True False True]]
我需要将其转换为 1 和 0,这样我就可以将元素与值张量相乘,即:
[[1. 0.64082676 0.90568966]
[0.64082676 1. 0.37999165]
[0.90568966 0.37999165 1. ]]
这两个功能我都试过了
masks = tf.map_fn(logical, masks, dtype=tf.float32)
masks = tf.vectorized_map(logical, masks)
与
@tf.function
def logical(x):
if tf.equal(x, True):
return zero
return one
但不幸的是没有运气。我也尝试直接与布尔张量相乘,但这是不允许的。
那么关于如何解决这个问题的任何指导?
【问题讨论】:
标签: python tensorflow machine-learning tensorflow2.0