以线条形式显示提升矩阵.想要将其更改为 Box

Displaying the Boost matrix in form of line. Want to change it to Box

本文关键字:Box 显示      更新时间:2023-10-16

//这个简单的程序初始化一个3x3矩阵并以line的形式输出它。

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main(){
  using namespace boost::numeric::ublas;
  matrix<double> m1(3,3);
 for(unsigned i=0;i<m1.size1();++i)
 for (unsigned j=0;j<m1.size2();++j)
     m(i,j)=3*i*j;
 std::cout<<m1<<std::endl;
return 0;
}
output
[3,3]((0,0,0),(0,3,6),(0,6,12)

你可以做这样的事情

void printMatrix(const matrix<double> &m)
{
    for(unsigned i=0;i<m.size1();++i)
    {
        cout<<"| ";
        for (unsigned j=0;j<m.size2();++j)
        {
            cout<<m(i,j)<<" | ";
        }
        cout<<"|"<<endl;
    }
}

这将打印如下内容:

| 0 | 0 | 0 |
| 0 | 3 | 6 |
| 0 | 6 | 9 |