【问题标题】:Indexing Armadillo cx_cube non-continuous rows索引犰狳 cx_cube 非连续行
【发布时间】:2019-08-20 16:10:36
【问题描述】:

我目前正在使用犰狳将 MATLAB 转换为 C++。我有一个有点大的 cx_cube,900x251x64,我有 uvec,“index”,我想用它来索引立方体:

data(index,:,:);//matlab version

看看犰狳的语法,我想到了这 2 个。

Q.subcube(first_row,first_col,first_slice,last_row,last_col, last_slice); //"index" may or may not be continuous so won't work
Q.rows(index); // not proper syntax

看来我只有两个选择

Q.elem( vector_of_indices )
Q( vector_of_indices )

但我不太确定他们将如何获取我需要的数字。

【问题讨论】:

    标签: cube armadillo


    【解决方案1】:

    通常在使用犰狳将 MATLAB 代码转换为 C++ 时,您希望根据您想要访问它的方式重新排序维度。 non-contiguous views for cubes 的 api 仅包括 Q.elem( vector_of_indices )Q( vector_of_indices ) 的单个元素访问,或 Q.slices( vector_of_slice_indices ) 的单个 slices 访问

    从您的 MATLAB 代码中,您似乎想使用索引向量访问 3D 数组中包含的各个矩阵。在这种情况下,指定切片索引的非连续视图将起作用。在将 MATLAB 代码转换为犰狳时,您需要做的就是使用第三维而不是第一维。也就是说,如果立方体的尺寸为 251x64x900,您可以轻松地将 251x64 尺寸的矩阵作为切片访问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多