mindspore.numpy.indices
- mindspore.numpy.indices(dimensions, dtype=mstype.int32, sparse=False)[源代码]
- 返回一个表示网格索引的数组。 计算一个数组,其中子数组包含仅沿相应轴变化的索引值0,1,…。 - 参数:
- dimensions (Union[list(int), tuple]) - 网格的shape。 
- dtype (mindspore.dtype, 可选) - 指定结果的数据类型。 
- sparse (boolean, 可选) - 返回网格的稀疏表示而非密集表示,默认值: - False。
 
- 返回:
- Tensor,或元素为Tensor的Tuple。如果 - sparse为- False,则返回一个网格索引数组:- grid.shape = (len(dimensions),) + tuple(dimensions)。如果- sparse为- True,则返回数组的Tuple,其中- grid[i].shape = (1, ..., 1, dimensions[i], 1, ..., 1),- dimensions[i]位于第- i个位置。
- 异常:
- TypeError - 如果输入的 - dimensions不是Tuple或List。
 
- 支持平台:
- 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]])]