c++ - 如何在犰狳 C++ 中修改矩阵中的某些列
问题描述
我在 Armadillo 10x10 矩阵中有一个非常简单的任务。任务是将列的值1,3,4
更改9
为sqrt(2)
.
我已经使用 (B is only one) 完成了任务
B.cols(columns) *= sqrt(2);
我为每一列都做了这个并且工作了。
这里的问题是阅读文档可以使用
B.cols( vector of col indices )
我想学习如何使用它,但似乎没有任何效果
解决方案
Declare the "vector of col indices" as uvec and put the column indices in it.
mat B(10, 11, fill::randu);
uvec column_indices = { 1, 3, 4, 9 };
B.cols(column_indices) *= sqrt(2);
(Just to be clear, C++ has zero-based indexing, so the first column has index 0, not 1).
推荐阅读
- ios - 如何使用 UICollectionView 的 selectItem 在 collectionView 单元格上绘图?
- android - 无法弄清楚 Android 中的布局依赖项
- git - 手动创建标记,例如 git merge 与来自差异的冲突
- android - 升级到 Android Gradle 插件 3.3.0 时出现无效的 Crashlytics API 密钥错误
- java - 如何更新 jlist swing java
- java - 如何将现有文件移动到新包中?
- python - 是否可以使用 python 的 Pool.map() 获得交互式反馈
- c# - 如何正确使用 TransactionScope 和 Nunit
- scala - 使用 Ebean 玩 Scala 2.6:访问实体字段会使 OneToMany 关联为空
- sql - 我们如何从 SQL 中的一个表中选择过滤后的值/记录?