Python模块NumPy中的tile(A,rep) 函数

from NumPy import *

函数形式: tile(A,rep)

功能:重复A的各个维度

参数类型:

- A: Array类的都可以

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

这个英文单词的本意是:贴瓷砖,还挺形象的。

举例:

tile([17,29],2),如果rep参数是一个整数,则表示重复A中的元素rep次,即行数(即维度)只有1维,所以2的意思是在“列”这个维度上重复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]]]])

上一篇:C#中一个简单的匹配16进制颜色的正则测试


下一篇:C语言数组初始化全部为0