从张量的形状中删除大小为 1 的维度。
用法
tf.squeeze(
input, axis=None, name=None
)参数
-
input一个Tensor。input要挤压。 -
axisints的可选列表。默认为[]。如果指定,仅压缩列出的尺寸。维度索引从 0 开始。挤压不是 1 的维度是错误的。必须在[-rank(input), rank(input))范围内。如果input是RaggedTensor,则必须指定。 -
name操作的名称(可选)。
返回
-
一个
Tensor。具有与input相同的类型。包含与input相同的数据,但删除了一个或多个大小为 1 的维度。
抛出
-
ValueError输入不能转换为张量,或者指定的轴不能被挤压。
给定一个张量 input ,此操作返回一个相同类型的张量,其中删除了所有大小为 1 的维度。如果您不想删除所有尺寸 1 的尺寸,您可以通过指定 axis 来删除特定的尺寸 1 尺寸。
例如:
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
tf.shape(tf.squeeze(t)) # [2, 3]
或者,要删除特定尺寸 1 尺寸:
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
tf.shape(tf.squeeze(t, [2, 4])) # [1, 2, 3, 1]
与旧的操作 tf.compat.v1.squeeze 不同,此操作不接受已弃用的 squeeze_dims 参数。
注意:如果 input 是 tf.RaggedTensor ,则此操作需要 O(N) 时间,其中 N 是压缩维度中的元素数。
相关用法
- Python tf.summary.scalar用法及代码示例
- Python tf.strings.substr用法及代码示例
- Python tf.strings.reduce_join用法及代码示例
- Python tf.sparse.cross用法及代码示例
- Python tf.sparse.mask用法及代码示例
- Python tf.strings.regex_full_match用法及代码示例
- Python tf.sparse.split用法及代码示例
- Python tf.strings.regex_replace用法及代码示例
- Python tf.signal.overlap_and_add用法及代码示例
- Python tf.strings.length用法及代码示例
- Python tf.strided_slice用法及代码示例
- Python tf.sparse.to_dense用法及代码示例
- Python tf.strings.bytes_split用法及代码示例
- Python tf.summary.text用法及代码示例
- Python tf.shape用法及代码示例
- Python tf.sparse.expand_dims用法及代码示例
- Python tf.signal.frame用法及代码示例
- Python tf.scatter_nd用法及代码示例
- Python tf.sparse.maximum用法及代码示例
- Python tf.signal.linear_to_mel_weight_matrix用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.squeeze。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
