On this page
numpy.append
- numpy.append(arr, values, axis=None)[source]
- 
    Append values to the end of an array. - Parameters
- 
      - arrarray_like
- 
        Values are appended to a copy of this array. 
- valuesarray_like
- 
        These values are appended to a copy of arr. It must be of the correct shape (the same shape asarr, excludingaxis). Ifaxisis not specified,valuescan be any shape and will be flattened before use.
- axisint, optional
- 
        The axis along which valuesare appended. Ifaxisis not given, botharrandvaluesare flattened before use.
 
- Returns
- 
      - appendndarray
- 
        A copy of arrwithvaluesappended toaxis. Note thatappenddoes not occur in-place: a new array is allocated and filled. Ifaxisis None,outis a flattened array.
 
 Examples>>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) array([1, 2, 3, ..., 7, 8, 9])When axisis specified,valuesmust 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)
© 2005–2020 NumPy Developers
Licensed under the 3-clause BSD License.
 https://numpy.org/doc/1.19/reference/generated/numpy.append.html