mindspore.numpy.unravel_index

mindspore.numpy.unravel_index(indices, shape, order='C')[源代码]

Converts a flat index or array of flat indices into a tuple of coordinate arrays.

说明

Out-of-bound indices are clipped by the boundaries of shape instead of raising an error.

参数
  • indices (Union[int, float, bool, list, tuple, Tensor]) – An integer array whose elements are indices into the flattened version of an array of dimensions shape.

  • shape (tuple of integers) – The shape of the array to use for unraveling indices.

  • order (Union['C', 'F'], optional) – Determines whether the indices should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order. Defaults to ‘C’.

返回

Tensor, each array in the tuple has the same shape as the indices array.

Supported Platforms:

Ascend GPU CPU

异常

ValueError – If order is not ‘C’ or ‘F’.

样例

>>> import mindspore.numpy as np
>>> print(np.unravel_index([22, 41, 37], (7,6)))
(Tensor(shape=[3], dtype=Int32, value= [3, 6, 6]),
Tensor(shape=[3], dtype=Int32, value= [4, 5, 1]))
>>> print(np.unravel_index([31, 41, 13], (7,6), order='F'))
(Tensor(shape=[3], dtype=Int32, value= [3, 6, 6]),
Tensor(shape=[3], dtype=Int32, value= [4, 5, 1]))