Does Pytorch have something similar to np.isin?

Hi, I want to replace all elements in a tensor that are equal to some values. In NumPy, I can simply do arr[np.isin(arr, some_values)] where some_values here is a list. Below can achieve what I need but is there any way not to use the for loop?

for v in [some_values]:
    arr[arr == v] = 0

arr[(arr[..., None] == [some_values]).any(-1)] = 0 works

2 Likes

Update on this. torch 1.10 now includes native support for isin. See: Function request: np.isin · Issue #3025 · pytorch/pytorch · GitHub