繁体   English   中英

减少张量流中张量的维度

[英]Reducing the dimensions of a tensor in tensorflow

我有一个具有以下形状的张量:

> tf.Tensor: shape=(1, 1440)

我如何减少这样的形状,以便我可以获得以下内容:

> tf.Tensor: shape=(1440,)

使用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,)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM