Repeats a 2D tensor. if `x` has shape (samples, dim) and `n` is `2`, the output will have shape `(samples, 2, dim)`. Arguments: x: Tensor or variable. n: Python integer, number of times to repeat. Returns: A tensor. Example: ```python >>> b = tf.constant([
(x, n)
| 2812 | |
| 2813 | @keras_export('keras.backend.repeat') |
| 2814 | def repeat(x, n): |
| 2815 | """Repeats a 2D tensor. |
| 2816 | |
| 2817 | if `x` has shape (samples, dim) and `n` is `2`, |
| 2818 | the output will have shape `(samples, 2, dim)`. |
| 2819 | |
| 2820 | Arguments: |
| 2821 | x: Tensor or variable. |
| 2822 | n: Python integer, number of times to repeat. |
| 2823 | |
| 2824 | Returns: |
| 2825 | A tensor. |
| 2826 | |
| 2827 | Example: |
| 2828 | ```python |
| 2829 | >>> b = tf.constant([[1, 2], [3, 4]]) |
| 2830 | >>> b |
| 2831 | <tf.Tensor: id=78, shape=(2, 2), dtype=int32, numpy= |
| 2832 | array([[1, 2], |
| 2833 | [3, 4]], dtype=int32)> |
| 2834 | >>> tf.keras.backend.repeat(b, n=2) |
| 2835 | <tf.Tensor: id=82, shape=(2, 2, 2), dtype=int32, numpy= |
| 2836 | array([[[1, 2], |
| 2837 | [1, 2]], |
| 2838 | [[3, 4], |
| 2839 | [3, 4]]], dtype=int32)> |
| 2840 | ``` |
| 2841 | """ |
| 2842 | assert ndim(x) == 2 |
| 2843 | x = array_ops.expand_dims(x, 1) |
| 2844 | pattern = array_ops.stack([1, n, 1]) |
| 2845 | return array_ops.tile(x, pattern) |
| 2846 | |
| 2847 | |
| 2848 | @keras_export('keras.backend.arange') |
nothing calls this directly
no test coverage detected