1

I have a matrix (say A) of dimension (k1, k2). I want to replicate it N times and save it into a 3D array or cube called B. As a result, the dimension of B will be (k1, k2, N).

In R, I did the following to do that:

B <- replicate(N, A)

I wonder if there is a function in Armadillo that can do that. Or, is looping the only way?

Thank you!

Paul
  • 107
  • 4

1 Answers1

3

You could avoid using a loop with the each_slice() method, but the cube must still be initialized beforehand:

arma::cube B(k1, k2, N);
B.each_slice() = A;

which has the advantage of conciseness.

operator
  • 155
  • 2
  • 7