np.mgrid 用法

Posted time-lcj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
‘‘‘

  

以上是关于np.mgrid 用法的主要内容,如果未能解决你的问题,请参考以下文章

Python基础:Numpy函数介绍:Meshgrid,mgrid,append等

Python基础:Numpy函数介绍:Meshgrid,mgrid,append等

Python基础:Numpy函数介绍:Meshgrid,mgrid,append等

numpy meshgrid 和 mgrid 的两个简单实例和解析

生成随机数的几个总结

python 画3D的高斯曲线