dpnp.append¶
- dpnp.append(arr, values, axis=None)[source]¶
Append values to the end of an array.
For full documentation refer to
numpy.append.- Parameters:
- arr{dpnp.ndarray, usm_ndarray}
Values are appended to a copy of this array.
- values{scalar, array_like}
These values are appended to a copy of arr. It must be of the correct shape (the same shape as arr, excluding axis). If axis is not specified, values can be any shape and will be flattened before use. These values can be in any form that can be converted to an array. This includes scalars, lists, lists of tuples, tuples, tuples of tuples, tuples of lists, and ndarrays.
- axis{None, int}, optional
The axis along which values are appended. If axis is not given, both arr and values are flattened before use.
Default:
None.
- Returns:
- outdpnp.ndarray
A copy of arr with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled. If axis is
None, out is a flattened array.
Warning
When axis is
None, a Python numeric scalar in values is converted to an array before the result dtype is chosen, so it can upcast arr (e.g. appending1to anint8array givesint64). This is deprecated: a future release will use the Python scalar promotion rules and keepint8. AFutureWarningis emitted when the result dtype will change. Wrap the scalar in a list to keep the current result, or convert it to an array of the desired dtype.See also
dpnp.insertInsert elements into an array.
dpnp.deleteDelete elements from an array.
Examples
>>> import dpnp as np >>> a = np.array([1, 2, 3]) >>> np.append(a, [[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.
>>> b = np.array([[1, 2, 3], [4, 5, 6]]) >>> np.append(b, [[7, 8, 9]], axis=0) array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> np.append(b, [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)