【发布时间】:2021-10-15 13:50:35
【问题描述】:
显示标题中提到的错误。
TypeError: @: 'numpy.ndarray' 和 'Tensor' 的操作数类型不受支持
使用 Ubuntu 和 VS Studio Code(新手)。
使用下面的代码:-
import numpy as np
import torch
inputs = np.array([[73, 67, 43],
[91, 88, 64],
[87, 134, 58],
[102, 43, 37],
[69, 96, 70]], dtype='float32')
targets = np.array([[56, 70],
[81, 101],
[119, 133],
[22, 37],
[103, 119]], dtype='float32')
w = torch.randn(2,3, requires_grad= True)
b = torch.randn(2, requires_grad = True)
print(w)
print(b)```
Works till here!
```def model(x):
return (x@w.t()+ b)
preds = model(inputs)
print(preds)```
Following the tutorial (But using VS Studio Code): https://jovian.ai/aakashns/02-linear-regression
#NewUser #Ubuntu #VSStudioCode
Intuition: The error is with '@' operator of PyTorch. Tried creating Tensors, working fine.
【问题讨论】:
-
把你的 numpy 数组转成 Tensor 应该没问题
-
有效。谢谢。
标签: python numpy ubuntu visual-studio-code torch