你好,你这个问题在错误提示中已经告诉你了,从np.array转tensor只支持它上面写的那些数字类型。我复现了你的代码,发现你的train_y的类型是object, 并且内容是字符串,这是无法转成tensor,tensor转化目前只支持满足上述类型的数字。如下图:
建议把label从str转化成数字,再转成tensor。
不知道你这个问题是否已经解决, 如果还没有解决的话:Numpy | PyTorch |
---|---|
np.put | |
x.put | x.put_ |
x = np.array([1, 2, 3])x.repeat(2) # [1, 1, 2, 2, 3, 3] | x = torch.tensor([1, 2, 3])x.repeat(2) # [1, 2, 3, 1, 2, 3]x.repeat(2).reshape(2, -1).transpose(1, 0).reshape(-1) # [1, 1, 2, 2, 3, 3] |
np.tile(x, (3, 2)) | x.repeat(3, 2) |
np.choose | |
np.sort | sorted, indices = torch.sort(x, [dim]) |
np.argsort | sorted, indices = torch.sort(x, [dim]) |
np.nonzero | torch.nonzero |
np.where | torch.where |
x[::-1] |