W3cubDocs

/TensorFlow 2.3

tf.keras.backend.flatten

View source on GitHub

Flatten a tensor.

Arguments
x A tensor or variable.
Returns
A tensor, reshaped into 1-D

Example:

b = tf.constant([[1, 2], [3, 4]])
b
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[1, 2],
       [3, 4]], dtype=int32)>
tf.keras.backend.flatten(b)
<tf.Tensor: shape=(4,), dtype=int32,
    numpy=array([1, 2, 3, 4], dtype=int32)>

© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/keras/backend/flatten