当我使用tensorflow RNN时,我遇到了这个问题。 这是我的包的版本:
Python version: 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609]
Packages versions:
numpy 1.12.1
tensorflow 1.1.0
代码是:
import tensorflow as tf
import numpy as np
from tensorflow.contrib import rnn
batches = 28
permutations = np.random.permutation(batches)
cell_class = rnn.BasicLSTMCell
cell = cell_class(200)
zero_state = cell.zero_state(batches, tf.float32)
with tf.Session() as sess:
state = sess.run(zero_state)
state[np.arange(batches)] = state[permutations]
我收到的消息:
Traceback (most recent call last):
File "test.py", line 15, in <module>
state[np.arange(batches)] = state[permutations]
TypeError: only integer scalar arrays can be converted to a scalar index
答案 0 :(得分:0)
您可以尝试使用以下行替换zero_state
值:
zero_state = cell.zero_state(batches, tf.float32)[0]
这似乎与Numpy的最新版本有关。最近的更改使得将单元素数组视为用于索引的标量的错误。