码迷,mamicode.com
首页 > 其他好文 > 详细

np.mgrid 用法

时间:2018-06-27 13:57:53      阅读:2698      评论:0      收藏:0      [点我收藏+]

标签:grid   axis   .sh   pre   用法   sha   int   one   shape   

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 用法

标签:grid   axis   .sh   pre   用法   sha   int   one   shape   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!