我在Tensorflow中创建了一个简单的数组变量,并试图找到一种方法来多次赋值。我知道为了在TF中执行赋值,您需要使用tf.assign
函数。问题是它返回的是“切片类型”,而不是变量类型。在
代码示例:
a = [-1.2, -5, 30.0, -7.5, 0.75]
v = tf.get_variable("v", shape=[5], initializer=tf.constant_initializer(a))
s = tf.Session()
c = c[0].assign(55) # Now c is not a regular variable anymore.
print(c) # <tf.Tensor 'strided_slice/_assign:0' shape=(5,) dtype=float32_ref>
s.run(c) # output: array([ 55. , -5. , 30. , -7.5 , 0.75], dtype=float32)
c = c[0].assign(66) # Trying to assign again to index 0 of array c
对于最后一行,我得到以下错误:
^{pr2}$我的问题是在Tensorflow中对一个变量进行多个赋值的正确方法是什么?在
只是不要将同一个python变量
c
用于不同的操作:相关问题 更多 >
编程相关推荐