Python中的 numpy.ma.row_stack()
numpy.ma.row_stack() :此函数有助于以垂直方式逐行堆叠数组。
参数 :
tup : sequence of ndarrays. 1D arrays must have same length, arrays must have the same shape along with all the axis.
结果 :
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.