numpy.tile(A, reps)
通过重复rep给出的次数来构造array
>>> a = np.array([0, 1, 2])
>>> np.tile(a, 2)
array([0, 1, 2, 0, 1, 2])
>>> np.tile(a, (2, 1))
array([[0, 1, 2],
[0, 1, 2]])
numpy.repeat(a, repeats, axis=None)
重复数组的元素
>>> np.repeat(3, 4)
array([3, 3, 3, 3])
>>> x = np.array([[1,2],[3,4]])
>>> np.repeat(x, 2)
array([1, 1, 2, 2, 3, 3, 4, 4])
>>> repeat(x,2,axis=0)
array([[1, 2],
[1, 2],
[3, 4],
[3, 4]])
>>> repeat(x,2,axis=1)
array([[1, 1, 2, 2],
[3, 3, 4, 4]])
>>> repeat(x, [1, 2], axis=0)
array([[1, 2],
[3, 4],
[3, 4]])
>>> repeat(x, [2, 1], axis=0)
array([[1, 2],
[1, 2],
[3, 4]])
tile()- 重复array
repeat()- 重复arry中的元素
网友评论