【问题标题】:How do you create an Array<octave_idx_type> in an .oct file?如何在 .oct 文件中创建 Array<octave_idx_type>?
【发布时间】:2015-06-16 19:13:10
【问题描述】:

我想使用 Array octave_idx_type 作为索引向量将矩阵插入到 NDArray(参见 stackoverflow 线程 here),如

A.insert( B , Array<octave_idx_type> ) ;

其中数组 A 是 3 维的。我知道我可以使用

A.insert( B , 0 , 0 ) ;

插入到第一个“页面”,但重要的是我能够在循环中插入 A 的其他页面,大概是通过在每个循环中更改页面的 idx_vector 值一次。

如何创建这个 idx_type 数组?

【问题讨论】:

标签: arrays indexing octave


【解决方案1】:

看看 Array C'tors:http://octave.sourceforge.net/doxygen41/d0/d26/classArray.html

你可以这样做

Array<octave_idx_type> p (dim_vector (3, 1));

作为独立示例:

int n = 2;
dim_vector dim(n, n, 3);
NDArray a_matrix(dim);

for (octave_idx_type i = 0; i < n; i++)
  for (octave_idx_type j = 0; j < n; j++)
    a_matrix(i,j, 1) = (i + 1) * 10 + (j + 1);

std::cout << a_matrix;

Matrix b_matrix = Matrix (n, n);
b_matrix(0, 0) = 1; 
b_matrix(0, 1) = 2; 
b_matrix(1, 0) = 3; 
b_matrix(1, 1) = 4; 
std::cout << b_matrix;

Array<octave_idx_type> p (dim_vector (3, 1), 0);
p(2) = 2;
a_matrix.insert (b_matrix, p);

std::cout << a_matrix;

最后一场比赛:

 0
 0
 0
 0
 11
 21
 12
 22
 1
 3
 2
 4

【讨论】:

    猜你喜欢
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 2017-05-21
    • 1970-01-01
    相关资源
    最近更新 更多