Can someone explain to me numpy.indices ()?

I read the documentation about np.indices () several times, but I cannot figure out what it is. I have used it many times to understand what he is doing, but I still cannot get it. Maybe the fact is that I'm starting to program, so I can not understand the idea of ​​words that describe this. In addition, I am not a native English speaker (although I have no problem with this). I would be very grateful for an easier explanation, perhaps with some example. Thank you

+6
source share
1 answer

Suppose you have a matrix M, the (i, j) th element is

M_ij = 2*i + 3*j 

One way to determine this matrix would be

 i, j = np.indices((2,3)) M = 2*i + 3*j 

what gives

 array([[0, 3, 6], [2, 5, 8]]) 

In other words, np.indices returns arrays that can be used as indexes. Elements in i indicate the row index:

 In [12]: i Out[12]: array([[0, 0, 0], [1, 1, 1]]) 

Elements in j indicate the column index:

 In [13]: j Out[13]: array([[0, 1, 2], [0, 1, 2]]) 
+7
source

All Articles