반응형
이 코드를 실행하려고합니다.
outputs, states = rnn.rnn(lstm_cell, x, initial_state=initial_state, sequence_length=real_length)
tensor_shape = outputs.get_shape()
for step_index in range(tensor_shape[0]):
word_index = self.x[:, step_index]
word_index = tf.reshape(word_index, [-1,1])
index_weight = tf.gather(word_weight, word_index)
outputs[step_index, :, :]=tf.mul(outputs[step_index, :, :] , index_weight)
하지만 마지막 줄에 오류가 발생합니다.
TypeError: 'Tensor' object does not support item assignment
텐서에 할당 할 수없는 것 같습니다. 어떻게 고칠 수 있습니까?
해결 방법
일반적으로 TensorFlow 텐서 객체는 할당 할 수 없기 때문에 * 할당의 왼쪽에서 사용할 수 없습니다.
outputs, states = rnn.rnn(lstm_cell, x, initial_state=initial_state,
sequence_length=real_length)
output_list = []
tensor_shape = outputs.get_shape()
for step_index in range(tensor_shape[0]):
word_index = self.x[:, step_index]
word_index = tf.reshape(word_index, [-1,1])
index_weight = tf.gather(word_weight, word_index)
output_list.append(tf.mul(outputs[step_index, :, :] , index_weight))
outputs = tf.stack(output_list)
참조 페이지 https://stackoverflow.com/questions/37697747
반응형
'파이썬' 카테고리의 다른 글
파이썬 What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow? (0) | 2020.11.03 |
---|---|
파이썬 Pandas는 문자열에서 숫자를 추출합니다. (0) | 2020.11.03 |
파이썬 how to indent the code block in Python IDE: Spyder? (0) | 2020.11.02 |
파이썬 장고 셸에서 모듈을 다시로드하는 방법은 무엇입니까? (0) | 2020.11.02 |
파이썬 Pandas-색인에 따라 값 바꾸기 (0) | 2020.11.02 |
댓글