Python 如何在tf.while\u循环体中分配通过循环变量传递的变量值?

Python 如何在tf.while\u循环体中分配通过循环变量传递的变量值?,python,tensorflow,Python,Tensorflow,这里的rawstate和v是使用tf.get\u variable() 现在, 如果我尝试这样做,它会抛出一个异常 def body(rawstate,x,v,coef): rawstate.assign_add(tf.matmul(x[v],coef[v])) v.assign_add(1) return [rawstate,x,v,coef] 那么如何在tf.while\u loop()body()中赋值呢?你检查过了吗:你试过使用tf.assign\u add吗?

这里的
rawstate
v
是使用
tf.get\u variable()

现在,

如果我尝试这样做,它会抛出一个异常

def body(rawstate,x,v,coef):
    rawstate.assign_add(tf.matmul(x[v],coef[v]))
    v.assign_add(1)
    return [rawstate,x,v,coef]

那么如何在
tf.while\u loop()
body()中赋值呢?

你检查过了吗:你试过使用tf.assign\u add吗?@amirbar def body(rawstate,x,v,coef):tf.assign\u add(rawstate,tf.matmul(x[v],coef[v]))tf.assign\u add(v,1)返回[rawstate,x,v,coef]这是“TypeError:传递给参数'begin'的值的数据类型float32不在允许值列表中:int32,int64”@Ayodhyankittpaul我认为这不是您检查的问题:您是否尝试使用tf.assign_add?@amirbar def body(rawstate,x,v,coef):tf.assign_add(rawstate,tf.matmul(x[v],coef[v]))tf.assign_add(v,1)返回[rawstate,x,v,coef]这是在抛出“TypeError:传递给参数'begin'的值的数据类型float32不在允许值列表中:int32,int64”@Ayodhyankittpaul我认为这不是问题所在
def body(rawstate,x,v,coef):
    rawstate.assign_add(tf.matmul(x[v],coef[v]))
    v.assign_add(1)
    return [rawstate,x,v,coef]
AttributeError: 'Tensor' object has no attribute 'assign_add'