我有多个 NxM 矩阵,想通过变量选择其中一个。我最好的猜测是使用 boost::MultiArray
创建一个 NxMxP 矩阵,然后通过三维选择。
我使用 array_view 实现了它:
typedef boost::multi_array<double, 3> threeDimMatrix;
typedef threeDimMatrix::index_range rangeDim;
threeDimMatrix hypotheses(boost::extents[nInputs][nStates][nChan]);
threeDimMatrix::array_view<2>::type hypothesesAdd =
hypotheses[boost::indices[rangeDim(0,2)][rangeDim(0,2)][ IDX ] ];
不幸的是,我想继续使用这个矩阵作为 boost::matrix
来编写我的代码,但不知道该怎么做。我可以做一些类似 Actor 的事情吗?
或者没有 multi_array 甚至可能吗?我还能以其他方式通过变量选择矩阵吗?
最佳答案
除了拥有一个 3 维数组,你不能只保持你的 Boost 矩阵原样并有一个映射器吗?这样就不需要类型转换了,你应该不会有任何问题。
映射器可以是一个基本数组,其中索引将是您的键,或者使用 C++ 库 cplusplus.com/reference/stl/map .
关于c++ - 通过变量从 boost::MultiArray 中选择一个 NxM 子矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10532401/