【发布时间】:2021-12-08 12:17:58
【问题描述】:
我有一个形状如下的张量:
> tf.Tensor: shape=(1, 1440)
如何减少这样的形状,以便得到以下结果:
> tf.Tensor: shape=(1440,)
【问题讨论】:
标签: python tensorflow
我有一个形状如下的张量:
> tf.Tensor: shape=(1, 1440)
如何减少这样的形状,以便得到以下结果:
> tf.Tensor: shape=(1440,)
【问题讨论】:
标签: python tensorflow
使用tf.squeeze:
import tensorflow as tf
tensor = tf.random.uniform((1, 1440))
print(tensor.shape
TensorShape([1, 1440])
现在:
squeezed = tf.squeeze(tensor)
print(squeezed.shape)
TensorShape([1440])
如果您真的想要形状的逗号格式,请将其转换为 NumPy:
tf.squeeze(s).numpy().shape
(1440,)
【讨论】: