This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How do I set an upper bound to the element of a matrix?

Tags: None
(comma "," separated)
kde-crazy
Registered Member
Posts
20
Karma
0
I mean I want to make all the element which is larger than a value x to be x.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
For a lower bound, if A is an Array:

A = A.max(x);

and if M is A Matrix:

M = M.array().max(x);

EDIT: For an upper bound, replace max by min.
kde-crazy
Registered Member
Posts
20
Karma
0
ggael wrote:If A is an Array:

A = A.max(x);

and if M is A Matrix:

M = M.array().max(x);


Thank you! So, is that a usual way to avoid inf before using M.array().exp()?
kde-crazy
Registered Member
Posts
20
Karma
0
ggael wrote:If A is an Array:

A = A.max(x);

and if M is A Matrix:

M = M.array().max(x);


It is strange, when I use max it acts like min, when I use min it acts like max.

Code: Select all
        MatrixXd x(2, 2);
   x(0, 0) = 800;
   x(0, 1) = 200;
   x(1, 0) = 30;
   x(1, 1) = 700;
   x = x.array().min(600);
   cout << x << endl;

the result is:
600 200
30 600


Code: Select all
        MatrixXd x(2, 2);
   x(0, 0) = 800;
   x(0, 1) = 200;
   x(1, 0) = 30;
   x(1, 1) = 700;
   x = x.array().max(600);
   cout << x << endl;


the result is
800 600
600 700
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Of course, if you want an upper bound you have to replace "max" by "min" in my answer. min (resp. max) return the minimum (resp. maximum) coefficient wise.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft