标量类型为Float的预期对象例外,但参数#2“ other”的标量类型为Long

时间:2019-11-23 17:50:43

标签: python pytorch tensor

运行以下代码时出现此错误,

  

标量类型为Float的预期对象,但标量类型Long为参数#2“ other”

    def encode(words):
        max_l = max([len(i) for i in words])
        result = torch.empty((1,max_l, 26)).int()
        for word in words:
            ints = (np.fromstring(word,dtype=np.uint8)-ord('a'))
            addition = np.zeros((max_l - ints.shape[0],)) -1
            tr = torch.Tensor(np.expand_dims(np.hstack((ints,addition)),-1))
            tr = (tr[:] == torch.arange(26)).int()
            tr = torch.unsqueeze(tr, 0)
            result = torch.cat((result,tr))
        result = result[1::]
        return result

,想知道如何解决?不幸的是,我没有完整的日志堆栈

0 个答案:

没有答案