E:\Anaconda\envs\pytorch\python.exe C:/Users/15492/PycharmProjects/pythonProject2/test-2.py Traceback (most recent call last): File "C:\Users\15492\PycharmProjects\pythonProject2\test-2.py", line 41, in <module> batch_x, batch_y = get_batch_data(batch_size) File "C:\Users\15492\PycharmProjects\pythonProject2\test-2.py", line 19, in get_batch_data batch_x = torch.random(batch_size) TypeError: 'module' object is not callable
时间: 2023-07-21 18:05:17 浏览: 342
Anaconda3-2022.10-Windows-x86-64.exe
这个错误提示说明你调用了 torch.random,但是 torch 模块中并没有名为 random 的函数或方法。你可能是想使用 torch.randn 函数来生成随机数,可以把调用 torch.random 改为 torch.randn:
``` python
batch_x = torch.randn(batch_size, input_size)
```
这样就可以生成一个大小为 batch_size x input_size 的随机张量。
阅读全文