Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TensorArray堆栈操作引发ValueError_Python_Tensorflow - Fatal编程技术网

Python TensorArray堆栈操作引发ValueError

Python TensorArray堆栈操作引发ValueError,python,tensorflow,Python,Tensorflow,我试图在while\u循环中使用tensorray,循环的每次迭代都会填充tensorray中的一项。下面是一个简单的例子: ta = tensor_array_ops.TensorArray(size=4, tensor_array_name='output_ta', dtype=tf.float32) time = tf.constant(0) def _call(time, ta): ta.write(time, tf.constant([1.,2.,3.,4.])) r

我试图在
while\u循环中使用
tensorray
,循环的每次迭代都会填充
tensorray
中的一项。下面是一个简单的例子:

ta = tensor_array_ops.TensorArray(size=4, tensor_array_name='output_ta', dtype=tf.float32)
time = tf.constant(0)

def _call(time, ta):
    ta.write(time, tf.constant([1.,2.,3.,4.]))
    return (time+1, ta)

_, t_out = tf.while_loop(
    cond=lambda time, _: time < 4,
    body=_call,
    loop_vars=(time, ta)
)
有人能看到我的代码有什么问题吗

编辑:这似乎只在渴望模式下发生。如果有人知道我如何修复它,使它在急切模式下工作,那就太好了。

ta=ta.write(时间,tf.constant([1,2,3,4]))

您使用的是什么版本的tensorflow?我刚刚用1.10尝试了你的例子,效果很好-唯一的区别是我将
tensor\u array\u ops.TensorArray
更改为
tf.TensorArray
一点解释就会使这段代码的答案更好。
t_out.stack()
>>>  Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor.