无法将NumPy数组转换为张量?

时间:2020-10-17 22:28:52

标签: machine-learning lstm recurrent-neural-network

我正在尝试创建一个使用LSTMS进行交易的代理,但是我遇到了一些冲突。

def batch_train(self, batch_size):
   batch = []
   for i in range(len(self.memory) - batch_size + 1, len(self.memory)):
      batch.append(self.memory[i])

for state, action, reward, next_state, done in batch:
  if not done:
    reward = reward + self.gamma * np.amax(self.model.predict(next_state)[0])
    
  target = self.model.predict(state)
  target[0][action] = reward
  
  self.model.fit(state, target, epochs=1, verbose=0)
  
if self.epsilon > self.epsilon_final:
  self.epsilon *= self.epsilon_decay

HERE CALL FUNCTION

if len(trader.memory) > batch_size:
  print(type(batch_size))
  trader.batch_train(batch_size) # error happens here

ValueError:无法将NumPy数组转换为张量(不支持 对象类型numpy.ndarray)。

1 个答案:

答案 0 :(得分:0)

您的数组是否为布尔值?如果还没有,请尝试将其转换为float32。

X = np.asarray(X).astype(np.float32)