5

一言で言えば、特定の基準を満たすテンソル内の要素のインデックスを提供するトーチにテンソル コマンドがあるかどうかを知りたいです。

トーチでできるようにしたいことを示すmatlabコードは次のとおりです。

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ループを使用してトーチでこれを実行できることは理解していますが、これをよりコンパクトに実行できるmatlabのfindコマンドに相当するものはありますか?

4

1 に答える 1

12
x[x:gt(5)] = 0

一般に、 x:gt :lt :ge :le :eq があります。

匿名関数を取り込んで各要素に適用する一般的な :apply 関数もあります。

于 2015-05-17T15:53:41.517 に答える