简而言之,我想知道torch中是否有一个张量命令,它可以为我提供满足特定标准的张量元素的索引。
这是 matlab 代码,它说明了我希望在 Torch 中能够做什么:
my_mat = magic(3); % returns a 3 by 3 matrix with the numbers 1 through 9
greater_than_fives = find(my_mat > 5); % find indices of all values greater than 5, the " > 5" is a logical elementwise operator that returns a matrix of all 0's and 1's and finally the "find" command picks out the indices with a "1" in them
my_mat(greater_than_fives) = 0; % set all values greater than 5 equal to 0
我知道我可以使用 for 循环在 Torch 中执行此操作,但是是否有一些等效于 matlab 的 find 命令可以让我更紧凑地执行此操作?