Python插件NumPy中的tile(A,rep) 函数

时间:2021-04-07 21:20:25

from NumPy import *

 

函数形式: tile(A,rep) 

功能:重复A的各个维度 

参数类型: 

- A: Array类的都可以 

- rep:A沿着各个维度重复的次数

举例:

tile([17,29],2)

输出[17,29,17,29]

 

tile([29,17],(3,5))

此时的(3,5)和[3,5]是相同的效果。

结果是3组,每组重复5次,也可以理解为二维表,3行,5列。先分3组(重复3次),每组重复5次。

array([[29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17]])

 

tile([29,17],[3,5,7])

结果是3组,每组一个二维表,每个二维表5行,7列,可以理解为三维表

array([[[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17, 29, 17]]])

 

tile([29,17],[3,5,7,4])

结果是4组,怎样理解?我也不知道,这已经超过了人类空间的认知。

依次分组,先分3组重复,然后分5组重复,然后分7组,最后重复4次。

如果5维会怎样?也是继续按组重复下去。先分5组,用中括号分隔。

array([[[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]]],

 

 

[[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]]],

 

 

[[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]],

 

[[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17],

[29, 17, 29, 17, 29, 17, 29, 17]]]])