TypeError: 'Tensor' object does not support item assignment in TensorFlow

后端 未结 4 1112
长情又很酷
长情又很酷 2020-11-28 09:46

I try to run this code:

outputs, states = rnn.rnn(lstm_cell, x, initial_state=initial_state, sequence_length=real_length)

tensor_shape = outputs.get_shape()         


        
4条回答
  •  暖寄归人
    2020-11-28 10:44

    When you have a tensor already, convert the tensor to a list using tf.unstack (TF2.0) and then use tf.stack like @mrry has mentioned. (when using a multi-dimensional tensor, be aware of the axis argument in unstack)

    a_list = tf.unstack(a_tensor)
    
    a_list[50:55] = [np.nan for i in range(6)]
    
    a_tensor = tf.stack(a_list)
    

提交回复
热议问题