TypeError: ‘torch.Size’ object is not callable解决方案:
在学习机器学习的过程中遇到了这样的问题:
def synthetic_data(w,b,num_examples):
x=torch.normal(0,1,(num_examples,len(w)))
y=torch.matmul(x,w)+b
y+=torch.normal(0,0.01,y.shape())
return x,y.reshape((-1,1))
true_w=torch.tensor([2,-3.4])
true_b=4.2
features,labels=synthetic_data(true_w,true_b,1000)
---
TypeError: 'torch.Size' object is not callable
原因分析:
翻译:torch.Size函数不可调用。
解决方案:
解决方法:
将y.shape()替换为y.size()
y+=torch.normal(0,0.01,y.size())
成功解决。