import numpy as np
anchors=np.ones((2,3))
anchor = np.broadcast_to(anchors, (5,)+anchors.shape) # 标红字体表达较为新颖(个人认为)
print(anchor)
print('anchors=',anchor.shape)
print('(5,)+anchors.shape=',(5,)+anchors.shape)
print('(4,)+(5,)+anchors.shape=',(4,)+(5,)+anchors.shape)
结果如下:
[[[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]]
[[1. 1. 1.]
[1. 1. 1.]]]
anchors= (5, 2, 3)
(5,)+anchors.shape= (5, 2, 3)
(4,)+(5,)+anchors.shape= (4, 5, 2, 3)