intmain() { Array22f m; m<< 1,2, 3,4; Array44f a = Array44f::Constant(0.6); cout<<"Here is the array a:"<<endl<<a<<endl<<endl; a.block<2,2>(1,1) = m; cout<<"Here is now a with m copied into its central 2x2 block:"<<endl<<a<<endl<<endl; a.block(0,0,2,3) = a.block(2,1,2,3); cout<<"Here is now a with bottom-right 2x3 block copied into top-left 2x2 block:"<<endl<<a<<endl<<endl; }
执行结果如下:
Here is the array a: 0.60.60.60.6 0.60.60.60.6 0.60.60.60.6 0.60.60.60.6
Here is now a with m copied into its central 2x2 block: 0.60.60.60.6 0.6120.6 0.6340.6 0.60.60.60.6
Here is now a with bottom-right 2x3 block copied into top-left 2x2 block: 340.60.6 0.60.60.60.6 0.6340.6 0.60.60.60.6
intmain() { MatrixXf m(3,3); m<< 1,2,3, 4,5,6, 7,8,9; cout<<"Here is the matrix m:"<<endl<<m<<endl; cout<<"2nd Row:"<<m.row(1)<<endl; m.col(2) += 3*m.col(0); cout<<"After adding 3 times the first column into third column,the matrix m is:\n"; cout<<m<<endl; }
执行结果如下:
Here is the matrix m: 123 456 789 2nd Row:456 After adding 3 times the first column into third column,the matrix m is: 126 4518 7830