# How to iterate over indices of a matrix?

**URL:** https://community.konduit.ai/t/how-to-iterate-over-indices-of-a-matrix/808
**Category:** ND4J
**Created:** [August 21, 2020, 8:03am UTC](https://community.konduit.ai/t/how-to-iterate-over-indices-of-a-matrix/808 "2020-08-21T08:03:30Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![amirshamaei](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/amirshamaei/32/100_2.png) [@amirshamaei](https://community.konduit.ai/u/amirshamaei)
#### Post date: [August 21, 2020, 8:03am UTC](https://community.konduit.ai/t/how-to-iterate-over-indices-of-a-matrix/808/1 "2020-08-21T08:03:30Z")

</div>

Hi,  
In Python when we want to iterate over a matrix with an arbitrary dimension, we can use this line of code:

> for index in np.ndindex(data.shape[2:]):

in java, in an easy way, we can do it with a determined number of for loop, but the prerequisite is knowledge about the dimension. But in arbitrary dimensions, the algorithm must be more complicated.

Is there any built-in method in ND4J lib for iterating over indices?

P.S: I have already written a piece of code for this purpose if there is not such a method, how can I contribute in ND4J project?
