# Computing a mask using Conditions

**URL:** <https://community.konduit.ai/t/computing-a-mask-using-conditions/1771>\
**Category:** ND4J\
**Created:** [February 3, 2022, 1:54pm UTC](https://community.konduit.ai/t/computing-a-mask-using-conditions/1771 "2022-02-03T13:54:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mado89](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/mado89/32/712_2.png) [@mado89](https://community.konduit.ai/u/mado89)\
**Post date:** [February 3, 2022, 1:54pm UTC](https://community.konduit.ai/t/computing-a-mask-using-conditions/1771/1 "2022-02-03T13:54:49Z")

</div>

Hi, can someone help me how to formulate ‘advanced’ conditions with ND4J?  
For example:

- (s1 \> 1) & (s2 \< s1)

So when using  
INDArray s1 = Nd4j.create(new double {1, 2, 3, 4});  
INDArray s2 = Nd4j.create(new double {4, 3, 2, 1});

the expected output would be an array with [false, false, true, true]

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [February 28, 2022, 1:36pm UTC](https://community.konduit.ai/t/computing-a-mask-using-conditions/1771/2 "2022-02-28T13:36:39Z")

</div>

@mado89 Sorry missed this one.  
Please ping me if you don’t see anything.

For future users:

You would want to use where(…) to evaluate conditions and the bitwise operations for comparisons. Each ndarray has the following:  
lt  
lte  
gt  
gte  
for elementwise comparisons.  
For comparisons I would recommend using NDBitwise as follows:

```java
import org.nd4j.linalg.factory.ops.NDBitwise;
NDBitwise bitwise = new NDBitwise();
INDArray mask = bitwise.and(s1.gt(1.0),s2.lt(s1));

```

We also have where if you need that as well.
