當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy.unravel_index()用法及代碼示例

numpy.unravel_index()函數將平麵索引或平麵索引數組轉換為坐標數組的元組。

用法: numpy.unravel_index(indices, shape, order = ‘C’)
參數:
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.

返回:[ndarray的元組]元組中的每個數組都具有與indexs數組相同的形狀。

代碼1:

# 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) 

輸出:

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


代碼2:

# 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) 

輸出:

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

相關用法


注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.unravel_index() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。