如何在犰狳中获得反对角线视图?

时间:2016-07-09 02:25:28

标签: c++ armadillo

我想访问矩阵的anti-diagonals作为视图。犰狳有可能吗?

人们希望看到我的代码

vec get_antidiag (const mat & A, const uint k) {
    const uint n = A.n_rows;
    const uint m = A.n_cols;
    const uint start_row = max(0, static_cast<int>(k+1-m));
    const uint end_row = min(k, n-1);
    const uint len = end_row - start_row +1;
    vec v (len);
    for (uint i = 0; i < len; ++i) {
        v(i) = A(i+start_row, k-(i+start_row));
    }
    return v;
}

void set_antidiag (mat & A, const uint k, const vec v) {
    const uint n = A.n_rows;
    const uint m = A.n_cols;
    const uint start_row = max(0, static_cast<int>(k+1-m));
    const uint end_row = min(k, n-1);
    const uint len = end_row - start_row +1;
    for (uint i = 0; i < len; ++i) {
        A(i+start_row, k-(i+start_row)) = v(i);
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用diagvec()fliplr()来提取诊断

vec get_antidiag (const mat & A, const uint k) {
    mat B=A;
    B = fliplr(B);
    return diagvec(B,k);
}

没有找到任何设置诊断的东西......