Thank you for your reply:)
I check the shape of train_x_np and it is (2895, 30).I use torch.from_numpy(array) to create tensors and set drop_last =True, but it has the error :Expected object of scalar type Float but got scalar type Double for argument #4 'mat1', the same if I use t_x = x.view(-1, 30, 1). But I check the type of train_x using print(train_x.dtype), it istorch.float64 rather than double. Complete error is like this:
RuntimeError                              Traceback (most recent call last)
<ipython-input-13-9266d8119db2> in <module>
     79     for i,(x1,y1) in enumerate(trainloader):
     80         t_x1=x1.view(10,30,1)
---> 81         output=rnn(t_x1)
     82         loss_train=criterion(output,y1)
     83         optimizer.zero_grad()

D:\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
    487             result = self._slow_forward(*input, **kwargs)
    488         else:
--> 489             result = self.forward(*input, **kwargs)
    490         for hook in self._forward_hooks.values():
    491             hook_result = hook(self, input, result)

<ipython-input-13-9266d8119db2> in forward(self, x)
     59         self.out=nn.Sequential(nn.Linear(64,1))
     60     def forward(self,x):
---> 61         r_out,(h_n,h_c)=self.rnn(x,None)
     62         out=self.out(r_out[:,-1,:])
     63         return out

D:\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
    487             result = self._slow_forward(*input, **kwargs)
    488         else:
--> 489             result = self.forward(*input, **kwargs)
    490         for hook in self._forward_hooks.values():
    491             hook_result = hook(self, input, result)

D:\Anaconda3\lib\site-packages\torch\nn\modules\rnn.py in forward(self, input, hx)
    177         if batch_sizes is None:
    178             result = _impl(input, hx, self._flat_weights, self.bias, self.num_layers,
--> 179                            self.dropout, self.training, self.bidirectional, self.batch_first)
    180         else:
    181             result = _impl(input, batch_sizes, hx, self._flat_weights, self.bias,

RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #4 'mat1'