How to set ‘nan’ in Tensor to 0? Now I have a extremely inefficient method:
my_tensor_np = my_tensor.cpu().numpy() my_tensor_np [np.isnan(my_tensor_np )] = 0 my_tensor.copy_(torch.from_numpy(my_tensor_np ).cuda())
But copy tensor between gpu and cpu takes lots of time, so I need a more efficient way.
Anyone can help me? Thanks a lot!