点击查看代码
# python tile() 函数简单介绍
#
# 格式:tile(A,reps)
# * A:array_like 输入的array
# * reps:array_like A沿各个维度重复的次数
import numpy as np
A = [1, 2]
B = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(np.tile(A, 2))
# output
# [1 2 1 2]
print(np.tile(A, (2, 2)))
# output
# [[1 2 1 2]
# [1 2 1 2]]
print(np.tile(A, (2, 1)))
# output
# [[1 2]
# [1 2]]
print(np.tile(A, (1, 2)))
# #output
# [[1 2 1 2]]
print(np.tile(B, (2, 1)))
# output
# [[1 2 3]
# [4 5 6]
# [7 8 9]
# [1 2 3]
# [4 5 6]
# [7 8 9]]
print(np.tile(B, (1, 2)))
# output
# [[1 2 3 1 2 3]
# [4 5 6 4 5 6]
# [7 8 9 7 8 9]]
print(np.tile(B, (2, 2)))
# output
# [[1 2 3 1 2 3]
# [4 5 6 4 5 6]
# [7 8 9 7 8 9]
# [1 2 3 1 2 3]
# [4 5 6 4 5 6]
# [7 8 9 7 8 9]]