AttributeError: 模块“torch”没有属性“hstack”

Par*_*ane 4 python numpy pytorch

我正在关注文档的hstack.

a = torch.tensor([1, 2, 3])
b = torch.tensor([4, 5, 6])
torch.hstack((a,b))
Run Code Online (Sandbox Code Playgroud)

但我不断收到错误消息:

AttributeError: module 'torch' has no attribute 'hstack'
Run Code Online (Sandbox Code Playgroud)

这是导致此错误的火炬版本:

torch.__version__
'1.6.0+cpu'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Poe*_*tor 5

显然,您正在调用 PyTorch 版本中尚不存在的函数——这就是错误消息的内容。

您的链接指向与开发者预览相关的帮助页面:请注意.8.0a0+342069f左上角的版本号。单击时,单击此处查看最新稳定版本的文档。链接 - 出现错误消息。

此功能在火炬版本中可用1.8.0.--直到考虑使用torch.cat`dim=1'。

torch.cat([a,b], dim=1)  # a, b - 2d torch.Tensors
Run Code Online (Sandbox Code Playgroud)

  • 这样就可以解释了。不过,看起来 `torch.hstack` 实际上在 1.7.0 中可用,而不是 1.8.0。 (2认同)