How can I run a loop with a tensor as its range? (in tensorflow)

后端 未结 2 1426
一生所求
一生所求 2021-02-01 05:00

I want to have a for loop that the number of its iterations is depend on a tensor value. For example:

for i in tf.range(input_placeholder[1,1]):
  # do something         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 05:05

    The type of the return value of TensorFlow Python API functions, including tf.range is a Tensor. A Tensor is a symbolic handle to node in a graph that represents computation. You perform the actual computation by calling the eval method on a Tensor, or by passing the object to run method of a Session. In your case, perhaps what you intended to do was simply iterate over numpy's range.

    for in in np.range(...):
      # do something
    

提交回复
热议问题