错误代码:
if __name__ == '__main__':
data=torch.tensor(3.1416)
print(data.size(0))
网友解决方法: RuntimeError: dimension specified as 0 but tensor has no dimensions_qq_30468133的博客-CSDN博客 如果是数据不对,数据前面加一个[]扩起来就有size了
print( torch.tensor([3.1416]).size(0))
如果数据源不可控,我的解决方法:
data=torch.tensor(3.1416)
if (data.size() != torch.Size([])):
print(data.size(0))
data=torch.tensor([3.1416])
if (data.size() != torch.Size([])):
print(data.size(0))