Append values to the end of an array. 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 as `arr`, excludi
(arr, values, axis=None)
| 5591 | |
| 5592 | @array_function_dispatch(_append_dispatcher) |
| 5593 | def append(arr, values, axis=None): |
| 5594 | """ |
| 5595 | Append values to the end of an array. |
| 5596 | |
| 5597 | Parameters |
| 5598 | ---------- |
| 5599 | arr : array_like |
| 5600 | Values are appended to a copy of this array. |
| 5601 | values : array_like |
| 5602 | These values are appended to a copy of `arr`. It must be of the |
| 5603 | correct shape (the same shape as `arr`, excluding `axis`). If |
| 5604 | `axis` is not specified, `values` can be any shape and will be |
| 5605 | flattened before use. |
| 5606 | axis : int, optional |
| 5607 | The axis along which `values` are appended. If `axis` is not |
| 5608 | given, both `arr` and `values` are flattened before use. |
| 5609 | |
| 5610 | Returns |
| 5611 | ------- |
| 5612 | append : ndarray |
| 5613 | A copy of `arr` with `values` appended to `axis`. Note that |
| 5614 | `append` does not occur in-place: a new array is allocated and |
| 5615 | filled. If `axis` is None, `out` is a flattened array. |
| 5616 | |
| 5617 | See Also |
| 5618 | -------- |
| 5619 | insert : Insert elements into an array. |
| 5620 | delete : Delete elements from an array. |
| 5621 | |
| 5622 | Examples |
| 5623 | -------- |
| 5624 | >>> import numpy as np |
| 5625 | >>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]]) |
| 5626 | array([1, 2, 3, ..., 7, 8, 9]) |
| 5627 | |
| 5628 | When `axis` is specified, `values` must have the correct shape. |
| 5629 | |
| 5630 | >>> np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0) |
| 5631 | array([[1, 2, 3], |
| 5632 | [4, 5, 6], |
| 5633 | [7, 8, 9]]) |
| 5634 | |
| 5635 | >>> np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0) |
| 5636 | Traceback (most recent call last): |
| 5637 | ... |
| 5638 | ValueError: all the input arrays must have same number of dimensions, but |
| 5639 | the array at index 0 has 2 dimension(s) and the array at index 1 has 1 |
| 5640 | dimension(s) |
| 5641 | |
| 5642 | >>> a = np.array([1, 2], dtype=np.int_) |
| 5643 | >>> c = np.append(a, []) |
| 5644 | >>> c |
| 5645 | array([1., 2.]) |
| 5646 | >>> c.dtype |
| 5647 | float64 |
| 5648 | |
| 5649 | Default dtype for empty ndarrays is `float64` thus making the output of dtype |
| 5650 | `float64` when appended with dtype `int64` |
nothing calls this directly
no test coverage detected
searching dependent graphs…