若有幫助到你,記得點贊哦!
# -*- 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]]"""