python中的repmat

np.tile

Python numpy 下的 np.tile有些类似于 matlab 中的 repmat函数。不需要 axis 关键字参数,仅通过第二个参数便可指定在各个轴上的复制倍数。

>> a = np.arange(3)
>> np.tile(a, 2)
array([0, 1, 2, 0, 1, 2])
>> np.tile(a, (2, 2))
array([[0, 1, 2, 0, 1, 2],
       [0, 1, 2, 0, 1, 2]])

>> b = np.arange(1, 5).reshape(2, 2)
>> np.tile(b, 2)
array([[1, 2, 1, 2],
       [3, 4, 3, 4]])

# 等价于
>> np.tile(b, (1, 2))

猜你喜欢

转载自blog.csdn.net/qq_25964837/article/details/79619041