1.Tensor中的-1变成0
import torch import numpy as np data = np.asarray([1, 6, 133, 12, 17, 10, 184, 377, 7347, 2579, 15, 80, 390, 49, 7348, 309, 669, 4, 2, 2, -1, -1, -1, -1, -1]) data = torch.from_numpy(data) data = data.ne(-1).long() * data print('data:', data)