Append tensor `x2` to the end of tensor `x1`. Args: x1: First input tensor. x2: Second input tensor. axis: Axis along which tensor `x2` is appended to tensor `x1`. If `None`, both tensors are flattened before use. Returns: A tensor with the value
(
x1,
x2,
axis=None,
)
| 652 | |
| 653 | @keras_export(["keras.ops.append", "keras.ops.numpy.append"]) |
| 654 | def append( |
| 655 | x1, |
| 656 | x2, |
| 657 | axis=None, |
| 658 | ): |
| 659 | """Append tensor `x2` to the end of tensor `x1`. |
| 660 | |
| 661 | Args: |
| 662 | x1: First input tensor. |
| 663 | x2: Second input tensor. |
| 664 | axis: Axis along which tensor `x2` is appended to tensor `x1`. |
| 665 | If `None`, both tensors are flattened before use. |
| 666 | |
| 667 | Returns: |
| 668 | A tensor with the values of `x2` appended to `x1`. |
| 669 | |
| 670 | Examples: |
| 671 | >>> x1 = keras.ops.convert_to_tensor([1, 2, 3]) |
| 672 | >>> x2 = keras.ops.convert_to_tensor([[4, 5, 6], [7, 8, 9]]) |
| 673 | >>> keras.ops.append(x1, x2) |
| 674 | array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32) |
| 675 | |
| 676 | When `axis` is specified, `x1` and `x2` must have compatible shapes. |
| 677 | >>> x1 = keras.ops.convert_to_tensor([[1, 2, 3], [4, 5, 6]]) |
| 678 | >>> x2 = keras.ops.convert_to_tensor([[7, 8, 9]]) |
| 679 | >>> keras.ops.append(x1, x2, axis=0) |
| 680 | array([[1, 2, 3], |
| 681 | [4, 5, 6], |
| 682 | [7, 8, 9]], dtype=int32) |
| 683 | >>> x3 = keras.ops.convert_to_tensor([7, 8, 9]) |
| 684 | >>> keras.ops.append(x1, x3, axis=0) |
| 685 | Traceback (most recent call last): |
| 686 | ... |
| 687 | TypeError: Cannot concatenate arrays with different numbers of |
| 688 | dimensions: got (2, 3), (3,). |
| 689 | """ |
| 690 | if any_symbolic_tensors((x1, x2)): |
| 691 | return Append(axis=axis).symbolic_call(x1, x2) |
| 692 | return backend.numpy.append(x1, x2, axis=axis) |
| 693 | |
| 694 | |
| 695 | class Arange(Operation): |
nothing calls this directly
no test coverage detected
searching dependent graphs…