我需要从用户那里得到一个输入 N 并生成一个 N*N 矩阵.我如何声明矩阵?一般来说,数组和矩阵的大小应该在声明时固定,对吗?vector
怎么样?我以前从未使用过这个,所以我需要资深人士的建议.
I need to get an input N from the user and generate a N*N matrix. How can I declare the matrix? Generally, the size of the array and matrix should be fixed at the declaration, right?
What about vector<vector<int>>
? I never use this before so I need suggestion from veteran.
Boost 在其 uBLAS 库,并提供如下使用语法.
Boost implements matrices (supporting mathematical operations) in its uBLAS library, and provides usage syntax like the following.
#include <boost/numeric/ublas/matrix.hpp>
int main(int argc, char* argv[])
{
unsigned int N = atoi(argv[1]);
boost::matrix<int> myMatrix(N, N);
for (unsigned i = 0; i < myMatrix.size1 (); ++i)
for (unsigned j = 0; j < myMatrix.size2 (); ++j)
myMatrix(i, j) = 3 * i + j;
return 0;
}
这篇关于根据输入动态二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!