bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / append
_ArrayFunctionDispatcher
numpy:append
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py:5567
Signature
def append(arr, values, axis = None)Summary
Append values to the end of an array.
Parameters
arr: array_likeValues are appended to a copy of this array.
values: array_likeThese 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.axis: int, optionalThe axis along which
valuesare appended. Ifaxisis not given, botharrandvaluesare flattened before use.
Returns
append: ndarrayA copy of
arrwithvaluesappended toaxis. Note that append does not occur in-place: a new array is allocated and filled. Ifaxisis None,outis a flattened array.
Examples
import numpy as np np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])✓
array([1, 2, 3, 4, 5, 6, 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):
File "<doctest numpy:append[0]>", line 1, in <module>
np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/runner/dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py", line 5634, in append
return concatenate((arr, values), axis=axis)
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)
a = np.array([1, 2], dtype=int) c = np.append(a, []) c✓
array([1., 2.])
c.dtype
✗dtype('float64')
Default dtype for empty ndarrays is `float64` thus making the output of dtype
`float64` when appended with dtype `int64`See also
Aliases
numpy.append