numpy 数组维度重复
用重复的方式拓展数组维度
方法1: numpy.repeat
不如torch的直观,后续再研究
官方文档:https://numpy.org/doc/stable/reference/generated/numpy.repeat.html
用法:
numpy.repeat(a, repeats, axis=None)
方法2: numpy.tile
将一维特征重复拓展成二维,方便换算
最终用的方法:
a = np.array([1,2,3,4])
b = np.tile(a, (3, 1))
print(b.shape)
输出b:
array([[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4]])
a.shape: (4, )
b.shape: (3, 4)
参考
https://www.cjavapy.com/article/906/