tf.keras.ops.append
Stay organized with collections
Save and categorize content based on your preferences.
Append tensor x2
to the end of tensor x1
.
tf.keras.ops.append(
x1, x2, axis=None
)
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 values of x2 appended to x1 .
|
Examples:
x1 = keras.ops.convert_to_tensor([1, 2, 3])
x2 = keras.ops.convert_to_tensor([[4, 5, 6], [7, 8, 9]])
keras.ops.append(x1, x2)
array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)
When axis
is specified, x1
and x2
must have compatible shapes.
>>> x1 = keras.ops.convert_to_tensor([[1, 2, 3], [4, 5, 6]])
>>> x2 = keras.ops.convert_to_tensor([[7, 8, 9]])
>>> keras.ops.append(x1, x2, axis=0)
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]], dtype=int32)
>>> x3 = keras.ops.convert_to_tensor([7, 8, 9])
>>> keras.ops.append(x1, x3, axis=0)
Traceback (most recent call last):
...
TypeError: Cannot concatenate arrays with different numbers of
dimensions: got (2, 3), (3,).
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.ops.append\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/numpy.py#L447-L486) |\n\nAppend tensor `x2` to the end of tensor `x1`.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.keras.ops.numpy.append`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/append)\n\n\u003cbr /\u003e\n\n tf.keras.ops.append(\n x1, x2, axis=None\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|------------------------------------------------------------------------------------------------------------|\n| `x1` | First input tensor. |\n| `x2` | Second input tensor. |\n| `axis` | Axis along which tensor `x2` is appended to tensor `x1`. If `None`, both tensors are flattened before use. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tensor with the values of `x2` appended to `x1`. ||\n\n\u003cbr /\u003e\n\n#### Examples:\n\n x1 = keras.ops.convert_to_tensor([1, 2, 3])\n x2 = keras.ops.convert_to_tensor([[4, 5, 6], [7, 8, 9]])\n keras.ops.append(x1, x2)\n array([1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)\n\nWhen `axis` is specified, `x1` and `x2` must have compatible shapes. \n\n \u003e\u003e\u003e x1 = keras.ops.convert_to_tensor([[1, 2, 3], [4, 5, 6]])\n \u003e\u003e\u003e x2 = keras.ops.convert_to_tensor([[7, 8, 9]])\n \u003e\u003e\u003e keras.ops.append(x1, x2, axis=0)\n array([[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]], dtype=int32)\n \u003e\u003e\u003e x3 = keras.ops.convert_to_tensor([7, 8, 9])\n \u003e\u003e\u003e keras.ops.append(x1, x3, axis=0)\n Traceback (most recent call last):\n ...\n TypeError: Cannot concatenate arrays with different numbers of\n dimensions: got (2, 3), (3,)."]]