從張量的形狀中刪除大小為 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
