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

后端 未结 4 1105
长情又很酷
长情又很酷 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:36

    As this comment says, a workaround would be to create a NEW tensor with the previous one and a new one on the zones needed.

    1. Create a mask of shape outputs with 0's on the indices you want to replace and 1's elsewhere (Can work also with True and False)
    2. Create new matrix of shape outputs with the new desired value: new_values
    3. Replace only the needed indexes with: outputs_new = outputs* mask + new_values * (1 - mask)

    If you would provide me with an MWE I could do the code for you.

    A good reference is this note: How to Replace Values by Index in a Tensor with TensorFlow-2.0

提交回复
热议问题