numpy.ma.row_stack():此函數有助於按垂直順序逐行堆疊數組。
參數:
- tup : ndarray的序列。一維數組必須具有相同的長度,數組和所有軸的形狀必須相同。
結果:
Row-wise stacked arrays
代碼1:解釋row_stack()
# importing libraries
import numpy as np
# row_stacking array
a = np.array([1, 2, 3])
arr = np.ma.row_stack (a)
print ("arr : \n", arr)
# row_stacking array
b = np.array([[1], [2], [3]])
arr1 = np.ma.row_stack (b)
print ("\narr1 : \n", arr1)
輸出:
arr : [[1] [2] [3]] arr1 : [[1] [2] [3]]
代碼2:row_stack()生成錯誤
# importing libraries
import numpy as np
# row_stacking array
b = np.array([[1, 1], [2], [3]])
arr1 = np.ma.row_stack (b)
print ("\narr1 : \n", arr1)
輸出:
ValueError: all the input array dimensions except for the concatenation axis must match exactly.
相關用法
注:本文由純淨天空篩選整理自Mohit Gupta_OMG 大神的英文原創作品 numpy.ma.row_stack() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。