mindspore.numpy.indices
- mindspore.numpy.indices(dimensions, dtype=mstype.int32, sparse=False)[源代码]
Returns an array representing the indices of a grid.
Computes an array where the subarrays contain index values 0, 1, … varying only along the corresponding axis.
- 参数
dimensions (tuple or list of ints) – The shape of the grid.
dtype (
mindspore.dtype
, optional) – Data type of the result.sparse (boolean, optional) – Defaults to False. Return a sparse representation of the grid instead of a dense representation.
- 返回
Tensor or tuple of Tensor, If sparse is False, returns one array of grid indices,
grid.shape = (len(dimensions),) + tuple(dimensions)
. If sparse is True, returns a tuple of arrays, withgrid[i].shape = (1, ..., 1, dimensions[i], 1, ..., 1)
withdimensions[i]
in the ith place- 异常
TypeError – If input dimensions is not a tuple or list.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> import mindspore.numpy as np >>> grid = np.indices((2, 3)) >>> print(grid) [Tensor(shape=[2, 3], dtype=Int32, value= [[0, 0, 0], [1, 1, 1]]), Tensor(shape=[2, 3], dtype=Int32, value= [[0, 1, 2], [0, 1, 2]])]