Flatten a tensor. Arguments: x: A tensor or variable. Returns: A tensor, reshaped into 1-D Example: ```python >>> b = tf.constant([[1, 2], [3, 4]]) >>> b <tf.Tensor: id=102, shape=(2, 2), dtype=int32, numpy= array([[1, 2], [3, 4]], dtyp
(x)
| 2902 | |
| 2903 | @keras_export('keras.backend.flatten') |
| 2904 | def flatten(x): |
| 2905 | """Flatten a tensor. |
| 2906 | |
| 2907 | Arguments: |
| 2908 | x: A tensor or variable. |
| 2909 | |
| 2910 | Returns: |
| 2911 | A tensor, reshaped into 1-D |
| 2912 | |
| 2913 | Example: |
| 2914 | ```python |
| 2915 | >>> b = tf.constant([[1, 2], [3, 4]]) |
| 2916 | >>> b |
| 2917 | <tf.Tensor: id=102, shape=(2, 2), dtype=int32, numpy= |
| 2918 | array([[1, 2], |
| 2919 | [3, 4]], dtype=int32)> |
| 2920 | >>> tf.keras.backend.flatten(b) |
| 2921 | <tf.Tensor: id=105, shape=(4,), dtype=int32, |
| 2922 | numpy=array([1, 2, 3, 4], dtype=int32)> |
| 2923 | ``` |
| 2924 | """ |
| 2925 | return array_ops.reshape(x, [-1]) |
| 2926 | |
| 2927 | |
| 2928 | @keras_export('keras.backend.batch_flatten') |
no test coverage detected