简体   繁体   English

如何在犰狳 C++ 中修改矩阵中的某些列

[英]How to modify certain columns in a Matrix in Armadillo C++

I have a very simple task in an Armadillo 10x10 matrix.我在 Armadillo 10x10 矩阵中有一个非常简单的任务。 The task is to change the values of the columns 1,3,4 and 9 to sqrt(2) .任务是将列1,3,49的值更改为sqrt(2)

I already done the task using (B is only ones)我已经使用 (B is only one) 完成了任务

B.cols(columns) *= sqrt(2);

I did this for every column and worked.我为每一列都做了这个并且工作了。

The problem here is that reading the documentation you can make this operation using这里的问题是阅读文档可以使用

B.cols( vector of col indices )

and I want to learn how to use it but nothing seems to work我想学习如何使用它,但似乎没有任何效果

Declare the "vector of col indices" as uvec and put the column indices in it.将“col 索引向量”声明为uvec并将列索引放入其中。

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). (需要说明的是,C++ 具有从零开始的索引,因此第一列的索引为 0,而不是 1)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM