numpy.unravel_index() function | Python

numpy.unravel_index() function converts a flat index or array of flat indices into a tuple of coordinate arrays.

Syntax : numpy.unravel_index(indices, shape, order = ‘C’)
Parameters :
indices : [array_like] An integer array whose elements are indices into the flattened version of an array of dimensions shape.
shape : [tuple of ints] The shape of the array to use for unraveling indices.
order : [{‘C’, ‘F’}, optional] Determines whether the multi-index should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.

Return : [tuple of ndarray] Each array in the tuple has the same shape as the indices array.

Code #1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program explaining
# numpy.unravel_index() function
  
# importing numpy as geek 
import numpy as geek
  
gfg = geek.unravel_index([22, 41, 37], (7, 6))
  
print(gfg) 

chevron_right


Output :

(array([3, 6, 6]), array([4, 5, 1]))

 
Code #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program explaining
# numpy.unravel_index() function
  
# importing numpy as geek 
import numpy as geek
  
gfg = geek.unravel_index([22, 41, 37], (7, 6), order = 'F')
  
print(gfg) 

chevron_right


Output :

(array([1, 6, 2]), array([3, 5, 5]))
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.