首页 > 其他 > 详细

np.mgrid 用法

时间:2018-06-27 13:09:05      阅读:829      评论:0      收藏:0      [点我收藏+]
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)
‘‘‘

  

np.mgrid 用法

原文:https://www.cnblogs.com/Time-LCJ/p/9233370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!