Python Tensorflow 2中tf.variable的条件赋值
为了努比,我们有Python Tensorflow 2中tf.variable的条件赋值,python,python-3.x,conditional-statements,tensorflow2.0,Python,Python 3.x,Conditional Statements,Tensorflow2.0,为了努比,我们有 threshold = 3 a = np.array([1,2,3,4,5,6]) a[a>=3] = 199 # a is [1, 2, 199, 199, 199, 199] 如何在tensorflow 2中编写类似的代码 b = tf.Variable(a) 谢谢。当然,您可以使用来有条件地设置值: b = tf.Variable(a) tf.where(b >= 3, 199, b) # <tf.Tensor: shape=(6,), dtype
threshold = 3
a = np.array([1,2,3,4,5,6])
a[a>=3] = 199
# a is [1, 2, 199, 199, 199, 199]
如何在tensorflow 2中编写类似的代码
b = tf.Variable(a)
谢谢。当然,您可以使用来有条件地设置值:
b = tf.Variable(a)
tf.where(b >= 3, 199, b)
# <tf.Tensor: shape=(6,), dtype=int64, numpy=array([ 1, 2, 199, 199, 199, 199])>
b=tf.变量(a)
其中(b>=3199,b)
#
Hi@cs95,谢谢你的回答。tf.where(b>=3199,b)
是否会被插入到计算图中,并影响b
在后支撑中的梯度?“谢谢,”杰森不能肯定地告诉你,对不起。也许你可以提出一个后续问题。当然,问题就在这篇文章中@jason祝你好运,我会看看我是否能做任何挖掘。