c++ - 等价于 Matlab 的 sum(A)?

标签 c++ eigen eigen3

如何获取行 vector ,其每个值是 Eigen 中二维 Array 的每一列的总和?

我想要 Matlab sum 函数的等价物,即

>> x = [1,2,3;4,5,6]

x =

     1.0000e+000     2.0000e+000     3.0000e+000
     4.0000e+000     5.0000e+000     6.0000e+000

>> sum (x)

ans =

     5.0000e+000     7.0000e+000     9.0000e+000

我可以使用 colwise 以某种方式做到这一点吗?

最佳答案

您可以使用 m.colwise().sum()

参见将部分归约与其他操作相结合部分here .

关于c++ - 等价于 Matlab 的 sum(A)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52279512/

相关文章:

c++ - 在特征库中的大矩阵中创建子矩阵

Visual Studio 2012 : LPCWSTR and wstring 中的 C++ 编译错误

C++ STL : Custom sorting one vector based on contents of another

c++ - 为什么我在使用 for 循环和 cout 命令时没有打印出 vector

c++ - 将标量添加到 Eigen::SparseMatrix 的每个非零条目

c++ - 通过引用传递的特征参数

c++ - 无堆粉刺。不正确还是迷信?

c++ - 如何在 CUDA 内核中使用 Eigen

c++ - Eigen::MatrixXd 到 flann::Matrix<double> 转换

c++ - 如何使用 eigen 编译 C++ 程序而不指定 -I 标志?