np.mgrid 用法

import numpy as np

dtype=np.float32
num_anchors = 6

y, x = np.mgrid[0:4, 0:4]
print(y)
print(x)
y = np.expand_dims(y, axis=-1) 
x = np.expand_dims(x, axis=-1)  
h = np.ones((num_anchors, ), dtype=dtype)  
w = np.ones((num_anchors, ), dtype=dtype)  
xmin = x - h / 2.
ymin = y - h / 2.
print(‘xmin‘)
print(xmin)
print(‘ymin‘)
print(ymin)
print(ymin.shape)

‘‘‘
[[0 0 0 0]
 [1 1 1 1]
 [2 2 2 2]
 [3 3 3 3]]
[[0 1 2 3]
 [0 1 2 3]
 [0 1 2 3]
 [0 1 2 3]]
xmin
[[[-0.5 -0.5 -0.5 -0.5 -0.5 -0.5]
  [ 0.5  0.5  0.5  0.5  0.5  0.5]
  [ 1.5  1.5  1.5  1.5  1.5  1.5]
  [ 2.5  2.5  2.5  2.5  2.5  2.5]]

 [[-0.5 -0.5 -0.5 -0.5 -0.5 -0.5]
  [ 0.5  0.5  0.5  0.5  0.5  0.5]
  [ 1.5  1.5  1.5  1.5  1.5  1.5]
  [ 2.5  2.5  2.5  2.5  2.5  2.5]]

 [[-0.5 -0.5 -0.5 -0.5 -0.5 -0.5]
  [ 0.5  0.5  0.5  0.5  0.5  0.5]
  [ 1.5  1.5  1.5  1.5  1.5  1.5]
  [ 2.5  2.5  2.5  2.5  2.5  2.5]]

 [[-0.5 -0.5 -0.5 -0.5 -0.5 -0.5]
  [ 0.5  0.5  0.5  0.5  0.5  0.5]
  [ 1.5  1.5  1.5  1.5  1.5  1.5]
  [ 2.5  2.5  2.5  2.5  2.5  2.5]]]
ymin
[[[-0.5 -0.5 -0.5 -0.5 -0.5 -0.5]
  [-0.5 -0.5 -0.5 -0.5 -0.5 -0.5]
  [-0.5 -0.5 -0.5 -0.5 -0.5 -0.5]
  [-0.5 -0.5 -0.5 -0.5 -0.5 -0.5]]

 [[ 0.5  0.5  0.5  0.5  0.5  0.5]
  [ 0.5  0.5  0.5  0.5  0.5  0.5]
  [ 0.5  0.5  0.5  0.5  0.5  0.5]
  [ 0.5  0.5  0.5  0.5  0.5  0.5]]

 [[ 1.5  1.5  1.5  1.5  1.5  1.5]
  [ 1.5  1.5  1.5  1.5  1.5  1.5]
  [ 1.5  1.5  1.5  1.5  1.5  1.5]
  [ 1.5  1.5  1.5  1.5  1.5  1.5]]

 [[ 2.5  2.5  2.5  2.5  2.5  2.5]
  [ 2.5  2.5  2.5  2.5  2.5  2.5]
  [ 2.5  2.5  2.5  2.5  2.5  2.5]
  [ 2.5  2.5  2.5  2.5  2.5  2.5]]]
(4, 4, 6)
‘‘‘

  

文章来自:https://www.cnblogs.com/Time-LCJ/p/9233370.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3