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. Parameters ---------- dimensions : sequence of ints The shape of the grid. dtype : dtype, optional
(dimensions, dtype=int, sparse=False)
| 1672 | |
| 1673 | @set_module('numpy') |
| 1674 | def indices(dimensions, dtype=int, sparse=False): |
| 1675 | """ |
| 1676 | Return an array representing the indices of a grid. |
| 1677 | |
| 1678 | Compute an array where the subarrays contain index values 0, 1, ... |
| 1679 | varying only along the corresponding axis. |
| 1680 | |
| 1681 | Parameters |
| 1682 | ---------- |
| 1683 | dimensions : sequence of ints |
| 1684 | The shape of the grid. |
| 1685 | dtype : dtype, optional |
| 1686 | Data type of the result. |
| 1687 | sparse : boolean, optional |
| 1688 | Return a sparse representation of the grid instead of a dense |
| 1689 | representation. Default is False. |
| 1690 | |
| 1691 | .. versionadded:: 1.17 |
| 1692 | |
| 1693 | Returns |
| 1694 | ------- |
| 1695 | grid : one ndarray or tuple of ndarrays |
| 1696 | If sparse is False: |
| 1697 | Returns one array of grid indices, |
| 1698 | ``grid.shape = (len(dimensions),) + tuple(dimensions)``. |
| 1699 | If sparse is True: |
| 1700 | Returns a tuple of arrays, with |
| 1701 | ``grid[i].shape = (1, ..., 1, dimensions[i], 1, ..., 1)`` with |
| 1702 | dimensions[i] in the ith place |
| 1703 | |
| 1704 | See Also |
| 1705 | -------- |
| 1706 | mgrid, ogrid, meshgrid |
| 1707 | |
| 1708 | Notes |
| 1709 | ----- |
| 1710 | The output shape in the dense case is obtained by prepending the number |
| 1711 | of dimensions in front of the tuple of dimensions, i.e. if `dimensions` |
| 1712 | is a tuple ``(r0, ..., rN-1)`` of length ``N``, the output shape is |
| 1713 | ``(N, r0, ..., rN-1)``. |
| 1714 | |
| 1715 | The subarrays ``grid[k]`` contains the N-D array of indices along the |
| 1716 | ``k-th`` axis. Explicitly:: |
| 1717 | |
| 1718 | grid[k, i0, i1, ..., iN-1] = ik |
| 1719 | |
| 1720 | Examples |
| 1721 | -------- |
| 1722 | >>> grid = np.indices((2, 3)) |
| 1723 | >>> grid.shape |
| 1724 | (2, 2, 3) |
| 1725 | >>> grid[0] # row indices |
| 1726 | array([[0, 0, 0], |
| 1727 | [1, 1, 1]]) |
| 1728 | >>> grid[1] # column indices |
| 1729 | array([[0, 1, 2], |
| 1730 | [0, 1, 2]]) |
| 1731 |
no test coverage detected