eigen 列拼接_使用Eigen C ++库将每个矩阵列与每个向量元素相乘

本文介绍了如何使用Eigen C++库将每个矩阵的列与每个向量元素相乘,展示了正确的代码实现和解释,包括如何处理行情况。
摘要由CSDN通过智能技术生成

I need to multiply each matrix column by each vector element using Eigen C++ library. I tried colwise without success.

Sample data:

Eigen::Matrix3Xf A(3,2); //3x2

A << 1 2,

2 2,

3 5;

Eigen::Vector3f V = Eigen::Vector3f(2, 3);

//Expected result

C = A.colwise()*V;

//C

//2 6,

//4 6,

//6 15

//this means C 1st col by V first element and C 2nd col by V 2nd element.

Matrix A can have 3xN and V Nx1. Meaning (cols x rowls).

解决方案

This is what I would do:

Code

Eigen::Matrix3Xf A(3, 2); // 3x2

A << 1, 2, 2, 2, 3, 5;

Eigen::Vector3f V = Eigen::Vector3f(1, 2, 3);

const Eigen::Matrix3Xf C = A.array().colwise() * V.array();

std::cout << C << std::endl;

Example output:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值