简体   繁体   English

C ++中矩阵的动态名称(Armadillo库)

[英]dynamic names of matrices in C++ (Armadillo library)

I want to generate k different random matrices in C++(with Armadillo library) where n is not fix at first and is an input in my function. 我想在C ++中生成k不同的随机矩阵(使用Armadillo库),其中n最初没有修复,并且是我函数中的输入。 It is easy in Armadillo to generate random matrices by using the following code within a for loop : 在Armadillo中,通过在for循环中使用以下代码来生成随机矩阵很容易:

 mat A = randu<mat>(n,n);

But since I need them in the next steps, I have to assign dynamic names or indexes for them, eg A1, A2, ... . 但由于我在接下来的步骤中需要它们,我必须为它们分配动态名称或索引,例如A1,A2,.... I want to know which method is the best one for this case except of using the pointers? 除了使用指针之外,我想知道哪种方法最适合这种情况?

It might be more convenient (and efficient, but have not tested) to instead use an armadillo cube: 使用犰狳立方体可能更方便(也更有效,但尚未经过测试):

cube A = randu<cube>(n,n,k);

A single matrix in this cube would then be accessed as A.slice(i) with 0 ≤ i ≤ k-1. 然后,该立方体中的单个矩阵将作为A.slice(i)被访问,其中A.slice(i) -1。 Just like matrices cubes can be resized at runtime, so you can dynamically change your n and k. 就像矩阵一样,可以在运行时调整大小,因此您可以动态更改n和k。 You can even preserve old values using A.resize(n',n',k') 您甚至可以使用A.resize(n',n',k')保留旧值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM