【发布时间】:2016-02-24 10:14:12
【问题描述】:
我有一个由 4 个浮点数组成的张量,称为 label。
我如何以 50% 的几率执行 x[0] = 1 - x[0]?
现在我有:
label = tf.constant([0.35, 0.5, 0.17, 0.14]) # just an example
uniform_random = tf.random_uniform([], 0, 1.0)
# Create a tensor with [1.0, 0.0, 0.0, 0.0] if uniform_random > 50%
# else it's only zeroes
inv = tf.pack([tf.round(uniform_random), 0.0, 0.0, 0.0])
label = tf.sub(inv, label)
label = tf.abs(label) # need abs because it inverted the other elements
# output will be either [0.35, 0.5, 0.17, 0.14] or [0.65, 0.5, 0.17, 0.14]
这可行,但看起来非常难看。没有更智能/更简单的方法吗?
相关问题:如何将某个操作(例如 sqrt)仅应用于两个元素?我猜我必须删除这两个元素,执行操作,然后将它们连接回原始向量?
【问题讨论】:
标签: tensorflow