在使用犰狳的立方体阵列(3D)时,我在使用col()或row()函数时遇到了一些困难 . 它们在任意2D矩阵(例如,A.col(0))上工作得很好,相关的cols()和rows()函数在多维数据集数组(如Q.cols(0,1);见下文),但row()和col()似乎不适用于此数据类型 . 这是一个最小的工作示例,输出包含在注释中:

#include <iostream>
    #include <armadillo>
    int main() {
        arma::Cube<double> Q(2,2,2,arma::fill::randu);
        Q.print();

    // [cube slice 0]
    //   0.7868   0.7107
    //   0.2505   0.9467
    // [cube slice 1]
    //   0.0193   0.2513
    //   0.4049   0.0227

    // The rows() and cols() function work fine to give me row- and columnwise access:

        Q.rows(0,0).print();

    // [cube slice 0]
    //   0.7868   0.7107
    // [cube slice 1]
    //   0.0193   0.2513

        Q.cols(0,0).print();

    // [cube slice 0]
    //   0.7868
    //   0.2505
    // [cube slice 1]
    //   0.0193
    //   0.4049

    // So far so good. I assumed row() and col() functions would
    // simply access single rows or columns, respectively, through 
    // the slices. But this is not the case. If I try to access 
    // the row() or col() functions via .print(), a core dump ensues.
    // If I examine the size of these objects, they are either
    // empty or extremely large.

        std::cout << size(Q.row(0)) << std::endl;
    // 0x0x0
        std::cout << size(Q.col(0)) << std::endl;
    // 0x0x18446744073709551615
        return 0;
    }

这表明我滥用这些函数(至少在Cube对象上),尽管文档显示Q.row(row_number)和Q.col(col_number)以这种方式使用 . 但是,如上所述,使用2D矩阵的.row()或.col()访问按预期工作 .

有人能告诉我问题是什么吗?