tensorflow repeat
时间: 2023-08-31 17:12:54 浏览: 41
The `tf.repeat()` function in TensorFlow is used to repeat the elements of a tensor in a specified number of times along a specified axis.
Syntax:
```python
tf.repeat(input, repeats, axis=None, name=None)
```
- `input`: The input tensor to repeat.
- `repeats`: A 1-D tensor or Python list containing the number of times to repeat each element of the `input` tensor. The length of this tensor should be equal to the size of the `axis` dimension of the `input` tensor.
- `axis`: The axis along which to repeat the elements of the input tensor. If `None`, the tensor is flattened and repeated. If Negative, it represents the axis to repeat from the end (e.g., -1 for the last axis).
- `name`: Optional name for the operation.
Example:
```python
import tensorflow as tf
x = tf.constant([1, 2, 3, 4])
y = tf.repeat(x, repeats=2, axis=0)
print(y) # Output: [1, 1, 2, 2, 3, 3, 4, 4]
z = tf.constant([[1, 2], [3, 4]])
w = tf.repeat(z, repeats=3, axis=1)
print(w) # Output: [[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4]]
```