Numpy的 tile() 函数,就是将原矩阵横向、纵向地复制。tile 是瓷砖的意思,顾名思义,这个函数就是把数组像瓷砖一样铺展开来。
举个例子,原矩阵:
mat = array([[1,2], [3, 4]])
横向:
tile(mat, (1, 4))
# 等同于
tile(mat, 4)
![](http://upload-images.jianshu.io/upload_images/8470638-ef934aaef57b1922.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/340)
image.png
结果:
[[1 2 1 2 1 2 1 2]
[3 4 3 4 3 4 3 4]]
纵向:
tile(mat, (3, 1))
![](http://upload-images.jianshu.io/upload_images/8470638-092c4fdc87e35e7d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/174)
image.png
结果:
[[1 2]
[3 4]
[1 2]
[3 4]
[1 2]
[3 4]]
横向 + 纵向
tile(mat, (3, 4))
![](http://upload-images.jianshu.io/upload_images/8470638-c172c16bc6aa29fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/395)
image.png
结果:
[[1 2 1 2 1 2 1 2]
[3 4 3 4 3 4 3 4]
[1 2 1 2 1 2 1 2]
[3 4 3 4 3 4 3 4]
[1 2 1 2 1 2 1 2]
[3 4 3 4 3 4 3 4]]
作者:切糕糕
链接:https://www.jianshu.com/p/9519f1984c70
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。