np.repeat:
# -*- coding: UTF-8 -*-
import numpy as np
a = [1, 2, 3]
b = np.repeat(a, 2)# 可以使用在普通列表a上,返回的是ndarray
print(a)
print(b)
b = b.repeat(3)# ndarray才有repeat属性
print(b)
# [1, 2, 3]
# [1 1 2 2 3 3]
# [1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3]
np.tile:
# -*- coding: UTF-8 -*-
import numpy as np
a = range(10)
a = np.tile(a, 2)
print(a)
# [0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9]
a = range(3)
a = np.tile(a, (3, 4))
print(a)
# [[0 1 2 0 1 2 0 1 2 0 1 2]
# [0 1 2 0 1 2 0 1 2 0 1 2]
# [0 1 2 0 1 2 0 1 2 0 1 2]]