How do you create an Array<octave_idx_type> in an .oct file?

我怕爱的太早我们不能终老 提交于 2019-12-25 01:08:34

问题


I'd like to use the Array octave_idx_type as an index vector to insert a matrix into an NDArray ( see stackoverflow thread here ) as in

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

where the array A is 3-dimensional. I know that I can use

A.insert( B , 0 , 0 ) ;

to insert into the first "page" but it is important that I be able to insert into the other pages of A in a loop, presumably by changing the idx_vector values for the page once in each loop.

How do I create this idx_type array?


回答1:


Hava a look at the Array C'tors: http://octave.sourceforge.net/doxygen41/d0/d26/classArray.html

You can do for example

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

as standalone example:

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;

the last cout:

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


来源:https://stackoverflow.com/questions/29572075/how-do-you-create-an-arrayoctave-idx-type-in-an-oct-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!