This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / _external / array_api_extra / _delegation / unravel_index

function

scipy._external.array_api_extra._delegation:unravel_index

source: build-install/usr/lib/python3.14/site-packages/scipy/_external/array_api_extra/_delegation.py:1670

Signature

def unravel_index(indices: Array, shape: tuple[int, ...], /, xp: ArrayNamespace | None = None) → tuple[Array, ...]

Summary

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

Parameters

indices : array

An integer array whose elements are indices into the flattened version of an array of dimensions shape.

shape : tuple of ints

The shape to use for unraveling indices.

xp : array_namespace, optional

The standard-compatible namespace for indices. Default: infer.

Returns

: tuple of array

A tuple of unraveled indices. Each array in the tuple has the same shape as the indices array.

Examples

import array_api_extra as xpx
import array_api_strict as xp
xs, ys = xpx.unravel_index(xp.asarray([1, 2, 4, 5, 6, 8]), (4, 3))
xs, ys
[(int(x), int(y)) for x, y in zip(xs, ys)]
xs, ys = xpx.unravel_index(xp.arange(6), (2, 2))
[(int(x), int(y)) for x, y in zip(xs, ys)]
⚠
Traceback (most recent call last):
  File "<doctest scipy._external.array_api_extra._delegation:unravel_index[0]>", line 1, in <module>
    [(int(x), int(y)) for x, y in zip(xs, ys)]
                                      ^^
NameError: name 'xs' is not defined

Aliases

  • scipy.differentiate.xpx.unravel_index