📜  numpy.indices()函数– Python

📅  最后修改于: 2022-05-13 01:55:13.124000             🧑  作者: Mango

numpy.indices()函数– Python

numpy.indices()函数返回一个表示网格索引的数组。计算一个数组,其中子数组包含索引值 0, 1, ... 仅沿相应轴变化。

代码#1:

# Python program explaining
# numpy.indices() function
       
# importing numpy as geek 
import numpy as geek 
   
gfg = geek.indices((2, 3))
  
print (gfg)

输出 :

[[[0 0 0]
  [1 1 1]]

 [[0 1 2]
  [0 1 2]]]


代码#2:

# Python program explaining
# numpy.indices() function
       
# importing numpy as geek 
import numpy as geek 
   
grid = geek.indices((2, 3))
gfg = grid[1]
  
print (gfg)

输出 :

[[0 1 2]
 [0 1 2]]