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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。