Vectorize "Greater than" operation

I want to do a simple operation using Octave, but I haven’t found a vectorized way to do it.

I will give a simple example:

A = [1,2,3; 4,5,6; 7,8,9];

b = [1,4,7];

% A>b ?

What I want is to check which values in the matrix A are greater than those in vector b. The results that I want to obtain are 3 binary matrices, one performing A>b(1), the 2nd A>b(2), and the last one A>b(3).

Can this be done avoiding using a loop?

Thanks in advance for any help!

You could probably reshape b into the 3rd dimension:

A > reshape(b, 1, 1, [])

That will return a 3d array where each slice corresponds to the binary matrices you are looking for.

3 Likes

I like this very clever solution.

Aaaah! :slight_smile:

Thank you for your reply! Smart move