# About ND4J Where() method

**URL:** <https://community.konduit.ai/t/about-nd4j-where-method/1069>\
**Category:** ND4J\
**Created:** [December 19, 2020, 10:26am UTC](https://community.konduit.ai/t/about-nd4j-where-method/1069 "2020-12-19T10:26:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akshay591](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Akshay591](https://community.konduit.ai/u/Akshay591)\
**Post date:** [December 19, 2020, 10:26am UTC](https://community.konduit.ai/t/about-nd4j-where-method/1069/1 "2020-12-19T10:26:13Z")

</div>

How do i get index where condition is matched.  
for ex -  
INDArray test = Nd4j.create(new double{2,3,5,6,7,8,9,5,6,2,3,2,2});  
if from test array i want index where number is equal to 2 , How will i get that ??

---

<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:** [December 20, 2020, 11:17pm UTC](https://community.konduit.ai/t/about-nd4j-where-method/1069/2 "2020-12-20T23:17:32Z")

</div>

> [@Akshay591](#):
>
> INDArray test = Nd4j.create(new double{2,3,5,6,7,8,9,5,6,2,3,2,2});

@Akshay591 could you reword your question a bit? Are you hoping to just get the index of elements matching a condition or using a numpy like where function where you return elements of 1 array or another? Eg: [numpy.where — NumPy v1.26 Manual](https://numpy.org/doc/stable/reference/generated/numpy.where.html)

---

<div class="post-metadata">

**Author:** ![Akshay591](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Akshay591](https://community.konduit.ai/u/Akshay591)\
**Post date:** [December 21, 2020, 8:47am UTC](https://community.konduit.ai/t/about-nd4j-where-method/1069/3 "2020-12-21T08:47:04Z")

</div>

@agibsonccc I want the Indexes of matching element , So according to the above example if the  
Condition = Conditions.equal(2) the Returned Array should Contain indexes which is [0,9,11,12] .

In Numpy we use to get the Indexes like this

test = np.array([2, 3, 5, 6, 7, 8, 9, 5, 6, 2, 3, 2, 2])

idx = np.where(test == 2)[0]

---

<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:** [December 22, 2020, 2:12am UTC](https://community.konduit.ai/t/about-nd4j-where-method/1069/4 "2020-12-22T02:12:57Z")

</div>

@Akshay591 ah I see.  
This is what you want:

```auto
        INDArray test = Nd4j.create(new double[] {2,3,5,6,7,8,9,5,6,2,3,2,2});
        INDArray falseArr = Nd4j.zeros(test.shape());
        INDArray other = Nd4j.ones(test.shape());
        INDArray[] result = Nd4j.where(test.eq(2),null,null);
        System.out.println(result[0]);

```

This invokes a numpy mode of Nd4j.where(…). You need to create a mask array. That’s what test.eq(2) does in this case.

---

<div class="post-metadata">

**Author:** ![Akshay591](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Akshay591](https://community.konduit.ai/u/Akshay591)\
**Post date:** [December 22, 2020, 10:07am UTC](https://community.konduit.ai/t/about-nd4j-where-method/1069/5 "2020-12-22T10:07:55Z")

</div>

@agibsonccc Working now, Thanks for the solution.
