numpy函数总结

1.stack

两个以上(n)相同array进行堆叠,n为axis的维度。

作用:用于Faster RCNN不同ratio的anchor生成。

a = np.array([[0, 0, 0], [4, 4, 4], [8, 8, 8]])
b = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
c = np.stack([a, b], axis=1)
print(c, c.shape)

输出:
[[[0 0 0]
  [1 1 1]]

 [[4 4 4]
  [2 2 2]]

 [[8 8 8]
  [3 3 3]]] (3, 2, 3)

 

2. meshgrid

a = np.array([1, 2, 3])
b = np.array([[4, 5, 6], [7, 8, 9]])
c, d = np.meshgrid(a, b)
print(c, c.shape)
print(d, d.shape)

输出:
[[1 2 3]
 [1 2 3]
 [1 2 3]
 [1 2 3]
 [1 2 3]
 [1 2 3]] (6, 3)
[[4 4 4]
 [5 5 5]
 [6 6 6]
 [7 7 7]
 [8 8 8]
 [9 9 9]] (6, 3)

 

3. flatten

a = np.array([[1, 2, 3], [4, 5, 6]])
b = a.flatten()
print(b)

输出:
[1 2 3 4 5 6]

 

4. broadcast_to

将array复制指定的倍数。

a = np.array([1, 2, 3])
b = np.broadcast_to(a, (3, 3))
print(b)

输出:
[[1 2 3]
 [1 2 3]
 [1 2 3]]

 

posted @ 2018-10-11 15:42  mjl_cv  阅读(430)  评论(0编辑  收藏  举报