MCPcopy Index your code
hub / github.com/numpy/numpy / indices

Function indices

numpy/_core/numeric.py:1726–1824  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1724
1725@set_module('numpy')
1726def indices(dimensions, dtype=int, sparse=False):
1727 """
1728 Return an array representing the indices of a grid.
1729
1730 Compute an array where the subarrays contain index values 0, 1, ...
1731 varying only along the corresponding axis.
1732
1733 Parameters
1734 ----------
1735 dimensions : sequence of ints
1736 The shape of the grid.
1737 dtype : dtype, optional
1738 Data type of the result.
1739 sparse : boolean, optional
1740 Return a sparse representation of the grid instead of a dense
1741 representation. Default is False.
1742
1743 Returns
1744 -------
1745 grid : one ndarray or tuple of ndarrays
1746 If sparse is False:
1747 Returns one array of grid indices,
1748 ``grid.shape = (len(dimensions),) + tuple(dimensions)``.
1749 If sparse is True:
1750 Returns a tuple of arrays, with
1751 ``grid[i].shape = (1, ..., 1, dimensions[i], 1, ..., 1)`` with
1752 dimensions[i] in the ith place
1753
1754 See Also
1755 --------
1756 mgrid, ogrid, meshgrid
1757
1758 Notes
1759 -----
1760 The output shape in the dense case is obtained by prepending the number
1761 of dimensions in front of the tuple of dimensions, i.e. if `dimensions`
1762 is a tuple ``(r0, ..., rN-1)`` of length ``N``, the output shape is
1763 ``(N, r0, ..., rN-1)``.
1764
1765 The subarrays ``grid[k]`` contains the N-D array of indices along the
1766 ``k-th`` axis. Explicitly::
1767
1768 grid[k, i0, i1, ..., iN-1] = ik
1769
1770 Examples
1771 --------
1772 >>> import numpy as np
1773 >>> grid = np.indices((2, 3))
1774 >>> grid.shape
1775 (2, 2, 3)
1776 >>> grid[0] # row indices
1777 array([[0, 0, 0],
1778 [1, 1, 1]])
1779 >>> grid[1] # column indices
1780 array([[0, 1, 2],
1781 [0, 1, 2]])
1782
1783 The indices can be used as an index into an array.

Callers 3

tril_indicesFunction · 0.90
triu_indicesFunction · 0.90
fromfunctionFunction · 0.85

Calls 2

emptyFunction · 0.85
reshapeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…