Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a logical operator over a boolean array?

I have duly searched the documentation and SE, but have failed to find out the solution: given an arbitrarily large vector of boolean values, how to return e.g. the logical AND of given values?

I would expect something like:

and([1 1 1])  -->  1

(since true && true && true gives 1). Of course, it is not valid syntax.

My aim is to find the fastest way to compare two binary vectors of the same size and return 1 if they are identical and 0 if not. Since the element-wise and returns a vector if used on two vectors hence the title question.

like image 210
István Zachar Avatar asked Nov 26 '25 10:11

István Zachar


1 Answers

Use all():

result = all(a == b);
like image 64
Oliver Charlesworth Avatar answered Nov 29 '25 01:11

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!