接上一期博客
numpy.append(arr, values, axis=None)
功能:
如果指定了axis
,则把arr
在axis
指定的维度进行切片,并把values
拼接在最后.
如果没有指定axis
,则把arr
和values
都做扁平化处理.
(要求values
在axis
指定的维度之外的其他维度和arr
有相同的形状)
参数
示例
>>>np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
array([1, 2, 3, ..., 7, 8, 9])
When axis
is specified, values
must have the correct shape.
>>>np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0)
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
>>>np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0)
Traceback (most recent call last):
...
ValueError: all the input arrays must have same number of dimensions, but
the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)