, dtype=<type 'int'>)

Return an array representing the indices of a grid.

Compute an array where the subarrays contain index values 0,1,... varying only along the corresponding axis.


dimensions : sequence of ints

The shape of the grid.

dtype : optional

Data_type of the result.


grid : ndarray

The array of grid indices, grid.shape = (len(dimensions),) + tuple(dimensions).

See also

mgrid, meshgrid


The output shape is obtained by prepending the number of dimensions in front of the tuple of dimensions, i.e. if dimensions is a tuple (r0, ..., rN-1) of length N, the output shape is (N,r0,...,rN-1).

The subarrays grid[k] contains the N-D array of indices along the k-th axis. Explicitly:

grid[k,i0,i1,...,iN-1] = ik


>>> grid = np.indices((2,3))
>>> grid.shape
>>> grid[0]        # row indices
array([[0, 0, 0],
       [1, 1, 1]])
>>> grid[1]        # column indices
array([[0, 1, 2],
       [0, 1, 2]])

Previous topic

Next topic

This Page

Quick search