溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python數(shù)組疊加函數(shù)怎么用

發(fā)布時間:2022-05-20 15:58:26 來源:億速云 閱讀:304 作者:iii 欄目:大數(shù)據(jù)

本文小編為大家詳細(xì)介紹“python數(shù)組疊加函數(shù)怎么用”,內(nèi)容詳細(xì),步驟清晰,細(xì)節(jié)處理妥當(dāng),希望這篇“python數(shù)組疊加函數(shù)怎么用”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學(xué)習(xí)新知識吧。

1、hstack代表水平方向疊加,要想疊加成功,行必須一致。

2、vstack代表垂直方向疊加。如果疊加成功,列必須一致。

3、concatenate手動指定疊加方向。

axis=0表示垂直方向疊加,axis=1表示水平方向疊加,axis=None表示一維數(shù)組疊加。

實(shí)例

import numpy as np
h1 = np.random.randint(0,10,size=(3,1))
h1 #結(jié)果:
'''array([[4],
       [8],
       [2]])'''
       
h2 = np.random.randint(0,10,size=(3,4))
h2 #結(jié)果:
'''array([[6, 9, 5, 0],
       [6, 1, 9, 4],
       [8, 8, 9, 8]])'''
h4 = np.random.randint(0,10,size=(1,4))
h4 # 結(jié)果
'''array([[2, 3, 5, 5]])'''
 
# 2.橫向堆疊
h3 = np.hstack([h1,h2])
h3 #結(jié)果:
'''array([[4, 6, 9, 5, 0],
       [8, 6, 1, 9, 4],
       [2, 8, 8, 9, 8]])'''
       
# 3.使用concatenate進(jìn)行自定義拼接
np.concatenate([h1,h2],axis=1) #橫向拼接 結(jié)果:
'''array([[4, 6, 9, 5, 0],
       [8, 6, 1, 9, 4],
       [2, 8, 8, 9, 8]])'''
       
# 3.使用concatenate進(jìn)行自定義堆疊
np.concatenate([h1,h2],axis=None)#拼接成一維數(shù)組 結(jié)果:
'''
array([4, 8, 2, 6, 9, 5, 0, 6, 1, 9, 4, 8, 8, 9, 8])
'''
# 3.使用concatenate進(jìn)行自定義堆疊
np.concatenate([h2,h3],axis=0)#縱向拼接 結(jié)果
'''array([[6, 9, 5, 0],
       [6, 1, 9, 4],
       [8, 8, 9, 8],
       [2, 3, 5, 5]])'''

讀到這里,這篇“python數(shù)組疊加函數(shù)怎么用”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點(diǎn)還需要大家自己動手實(shí)踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI