适用于MATLAB操作的Armadillo等效项 [英] Armadillo equivalent for MATLAB operations

查看:52
本文介绍了适用于MATLAB操作的Armadillo等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是犰狳的新手.我正在寻找与以下在MATLAB中执行的操作等效的Armadillo:

Hi I am new to armadillo. I am looking for the Armadillo equivalent for the following operation performed in MATLAB:

B(B_t>=0) = 1;
B(B_t<0) = -1;

这里B和B_t是两个具有相同维度的矩阵.我可以在这里使用犰狳信号函数(sign),但随后我需要将所有零元素设置为一个.我相信这是一个简单的问题.感谢您的帮助.

Here B and B_t are two matrices having same dimensions. I can use the armadillo signum function(sign) here but then I need to set all zero elements to one. I am sure this is a simple problem. Your help is appreciated.

还可以让我知道如何将犰狳矩阵中的非连续索引设置为特定值吗?

Also, can anyone let me know how to set non-contiguous indexes in an armadillo matrix to a particular value?

谢谢.

推荐答案

如果具有相同维度的两个矩阵A和B,则可以将A的所有元素(其中B的对应元素>> 0)设置为一个值与

If you have two matrices A and B of the same dimension you could set all of the elements of A where the corresponding element of B is > 0 to a value with

using namespace arma;

// A and B are matrices of the same shape.
mat A = randu<mat>(5,5) - 0.5;
mat B = randu<mat>(5,5) - 0.5;

// Change elements of A where B > 0 to 10.0
A.elem( find(B > 0) ).fill(10.0);

我们在其中使用查找生成了满足所需条件的指标列表. .elem 来创建A元素的视图.最后.fill 将这些元素设置为所需的值.

Where we have used find to produce a list of indicies that satisfy the desired criteria. .elem to then create a view of those elements of A. And finally .fill to set those elements to the desired value.

这篇关于适用于MATLAB操作的Armadillo等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆