tile()函数



若有帮助到你,记得点赞哦!

# -*- coding: utf-8 -*-
"""
Created on Thu Nov 16 19:13:21 2017

@author: Lelouch_C.C
"""
#tile()函数用来复制
import numpy as np
a = [[1,2,3],[4,5,5]]
b = np.tile(a,3)      #对a中每个元素进行复制3次后作为新的元素,复制后a的元素个数不变
print(b)
 
"""输出:
 [[1 2 3 1 2 3 1 2 3]
  [4 5 5 4 5 5 4 5 5]]"""
 
import numpy as np
a = [[1,2,3],[4,5,5]]
b = np.tile(a,(2,3)) #先对a中每个元素进行复制3次后作为新的元素,然后复制a两次,元素个数变为原来两倍
print(b)   #或先对a中进行复制2次后,元素变为原来的2倍,然后先对a中每个元素进行复制3次后作为新的元素
 
"""输出:
 [[1 2 3 1 2 3 1 2 3]
  [4 5 5 4 5 5 4 5 5]
  [1 2 3 1 2 3 1 2 3]
  [4 5 5 4 5 5 4 5 5]]"""
 
import numpy as np
a = np.mat([1,2,3])
b = np.tile(a,(2,1))#
print(b)
"""输出:
 [[1 2 3]
  [1 2 3]]"""

import numpy as np
a = [[1,2,3],[4,5,5]]
b = np.tile(a,(2,1))
print(b)
"""输出:
  [[1 2 3]
   [4 5 5]
   [1 2 3]
   [4 5 5]]"""

你可能感兴趣的:(python入门)