mindspore.numpy.ravel_multi_index

mindspore.numpy.ravel_multi_index(multi_index, dims, mode='clip', order='C')[源代码]

Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.

说明

raise mode is not supported. Default mode is clip.

参数
  • multi_index (tuple of array_like) – A tuple of integer arrays, one array for each dimension.

  • dims (Union[int, tuple of integers]) – The shape of array into which the indices from multi_index apply.

  • mode ({wrap, clip}) –

    Specifies how out-of-bounds indices are handled. Default: clip.

    • wrap: wrap around

    • clip: clip to the range

    In clip mode, a negative index which would normally wrap will clip to 0 instead.

  • order ({C, F}) – Determines whether the multi-index should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.

返回

Raveled_indices array. An array of indices into the flattened version of an array of dimensions dims.

异常
  • TypeError – If multi_index or dims can not be converted to tensor or dims is not a sequence of integer values.

  • ValueError – If the length of multi_index and that of dims are not equal.

Supported Platforms:

GPU

样例

>>> import mindspore.numpy as np
>>> arr = np.array([[3, 6, 6], [4, 5, 1]])
>>> output = np.ravel_multi_index(arr, (7, 6))
>>> print(output)
[22. 41. 37.]
>>> output = np.ravel_multi_index((3, 1, 4, 1), (6, 7, 8, 9))
>>> print(output)
1621.0