Lua-Torch的等效函数在Matlab中对应哪个find函数?

2026-06-05 11:455阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计308个文字,预计阅读时间需要2分钟。

Lua-Torch的等效函数在Matlab中对应哪个find函数?

简单来说,我想知道在 MATLAB 中是否存在张量命令,它能够给出张量满足某个标准的元素索引。这是 MATLAB 代码,说明了我想在张量中做什么:

my_mat=magic(3); % 返回一个 3x3 的矩阵,其数字这段代码创建了一个 3x3 的矩阵,其元素是按照幻方排列的。我期望能够在张量中执行类似操作。

简而言之,我想知道火炬中是否存在张量命令,它给出了张量满足某个标准的元素索引.

这是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命令可以让我更紧凑地执行此操作吗?

x[x:gt(5)] = 0

通常有x:gt:lt:ge:le:eq

还有一般:apply函数tha接收匿名函数并将其应用于每个元素.

Lua-Torch的等效函数在Matlab中对应哪个find函数?

本文共计308个文字,预计阅读时间需要2分钟。

Lua-Torch的等效函数在Matlab中对应哪个find函数?

简单来说,我想知道在 MATLAB 中是否存在张量命令,它能够给出张量满足某个标准的元素索引。这是 MATLAB 代码,说明了我想在张量中做什么:

my_mat=magic(3); % 返回一个 3x3 的矩阵,其数字这段代码创建了一个 3x3 的矩阵,其元素是按照幻方排列的。我期望能够在张量中执行类似操作。

简而言之,我想知道火炬中是否存在张量命令,它给出了张量满足某个标准的元素索引.

这是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命令可以让我更紧凑地执行此操作吗?

x[x:gt(5)] = 0

通常有x:gt:lt:ge:le:eq

还有一般:apply函数tha接收匿名函数并将其应用于每个元素.

Lua-Torch的等效函数在Matlab中对应哪个find函数?