Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ 2D vector and operations

How can one create a 2D vector in C++ and find its length and coordinates?

In this case, how are the vector elements filled with values?

Thanks.

like image 207
Simplicity Avatar asked May 18 '26 16:05

Simplicity


1 Answers

If your goal is to do matrix computations, use Boost::uBLAS. This library has many linear algebra functions and will probably be a lot faster than anything you build by hand.

If you are a masochist and want to stick with std::vector, you'll need to do something like the following:

std::vector<std::vector<double> > matrix;
matrix.resize(10);
matrix[0].resize(20);
// etc
like image 185
chrisaycock Avatar answered May 21 '26 07:05

chrisaycock



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!