Filter out np.nan values from pytorch 1d tensor
I have a 1d tensor looking kinda like this:

import numpy as np
import torch

my_list = [0, 1, 2, np.nan, np.nan, 4]
tensor = torch.Tensor(my_list)


How do i filter out the nan-values, so it becomes a tensor of size 4?

You can use torch.isnan

my_list = [0, 1, 2, np.nan, np.nan, 4]
tensor = torch.Tensor(my_list)

tensor[~torch.isnan(tensor)]
tensor([0., 1., 2., 4.])

