构造
Vector
1 #include <boost/numeric/ublas/vector.hpp> 2 #include <boost/numeric/ublas/io.hpp> 3 4 int main () { 5 using namespace boost::numeric::ublas; 6 vector<double> v (3); 7 for (unsigned i = 0; i < v.size (); ++ i) 8 v (i) = i; 9 std::cout << v << std::endl; 10 }
Matrix
#include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/io.hpp> int main () { using namespace boost::numeric::ublas; matrix<double> m (3, 3); for (unsigned i = 0; i < m.size1 (); ++ i) for (unsigned j = 0; j < m.size2 (); ++ j) m (i, j) = 3 * i + j; std::cout << m << std::endl; }