Python numpy.ma.row_stack()
numpy.ma.row_stack() :这个函数有助于以垂直的方式依次堆叠数组的行。
参数 :
tup :ndarrays的序列。一维数组必须有相同的长度,数组必须有相同的形状和所有的轴。
结果 :
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.