flopscope.numpy.append
fnp.append(arr, values, axis=None)[flopscope source][numpy source]
Append values to the end of an array.
Adapted from NumPy docs np.append
Append values to end of array. Cost: numel(values).
Parameters
- arr:array_like
Values are appended to a copy of this array.
- values:array_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.- axis:int, optional
The axis along which
valuesare appended. Ifaxisis not given, botharrandvaluesare flattened before use.
Returns
- append:ndarray
A 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.
See also
- we.flops.insert Insert elements into an array.
- we.flops.delete Delete elements from an array.
Examples
>>> import flopscope.numpy as fnp
>>> flops.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.
>>> flops.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0)
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])>>> flops.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)>>> a = flops.array([1, 2], dtype=int)
>>> c = flops.append(a, [])
>>> c
array([1., 2.])
>>> c.dtype
float64Default dtype for empty ndarrays is float64 thus making the output of dtype
float64 when appended with dtype int64