跨 SparseTensor 的維度計算元素的 tf.sparse.maximum
。
用法
tf.sparse.reduce_max(
sp_input, axis=None, keepdims=None, output_is_sparse=False, name=None
)
參數
-
sp_input
要減少的 SparseTensor。應該是數字類型。 -
axis
要減小的尺寸;列表或標量。如果None
(默認),減少所有維度。 -
keepdims
如果為真,則保留長度為 1 的縮減維度。 -
output_is_sparse
如果為真,則返回SparseTensor
而不是密集的Tensor
(默認值)。 -
name
操作的名稱(可選)。
返回
-
如果
output_is_sparse
為 True,則減少的張量或減少的 SparseTensor。
這是按元素tf.sparse.maximum
op 的歸約操作。
此 Op 采用 SparseTensor 並且是 tf.reduce_max()
的稀疏對應項。特別是,如果 output_is_sparse
是 False
,則此 Op 還返回密集的 Tensor
,如果 output_is_sparse
是 True
,則返回 SparseTensor
。
注意:該函數沒有定義梯度,因此不能用於需要梯度下降的訓練模型。
沿 axis
中給定的尺寸減少 sp_input
。除非 keepdims
為真,否則對於 axis
中的每個條目,張量的秩都會減少 1。如果 keepdims
為真,則保留縮減後的維度,長度為 1。
如果axis
沒有條目,則減少所有維度,並返回具有單個元素的張量。此外,軸可以是負數,類似於 Python 中的索引規則。
sp_input
中未定義的值不參與減少最大值,而不是隱式假設為 0 - 因此它可以為稀疏的 axis
返回負值。但是,如果 axis
中沒有值,它將減少到 0。請參見下麵的第二個示例。
例如:
'x' 代表 [[1, ?, 2]
[?, 3, ?]]
在哪裏 ?是implicitly-zero。
x = tf.sparse.SparseTensor([[0, 0], [0, 2], [1, 1]], [1, 2, 3], [2, 3])
tf.sparse.reduce_max(x)
<tf.Tensor:shape=(), dtype=int32, numpy=3>
tf.sparse.reduce_max(x, 0)
<tf.Tensor:shape=(3,), dtype=int32, numpy=array([1, 3, 2], dtype=int32)>
tf.sparse.reduce_max(x, 1)
<tf.Tensor:shape=(2,), dtype=int32, numpy=array([2, 3], dtype=int32)>
tf.sparse.reduce_max(x, 1, keepdims=True)
<tf.Tensor:shape=(2, 1), dtype=int32, numpy=
array([[2],
[3]], dtype=int32)>
tf.sparse.reduce_max(x, [0, 1])
<tf.Tensor:shape=(), dtype=int32, numpy=3>
'y' 代表 [[-7, ?]
[4、3]
[ ?, ?]
y = tf.sparse.SparseTensor([[0, 0,], [1, 0], [1, 1]], [-7, 4, 3],
[3, 2])
tf.sparse.reduce_max(y, 1)
<tf.Tensor:shape=(3,), dtype=int32, numpy=array([-7, 4, 0], dtype=int32)>
相關用法
- Python tf.sparse.reduce_sum用法及代碼示例
- Python tf.sparse.retain用法及代碼示例
- Python tf.sparse.reorder用法及代碼示例
- Python tf.sparse.reshape用法及代碼示例
- Python tf.sparse.cross用法及代碼示例
- Python tf.sparse.mask用法及代碼示例
- Python tf.sparse.split用法及代碼示例
- Python tf.sparse.to_dense用法及代碼示例
- Python tf.sparse.expand_dims用法及代碼示例
- Python tf.sparse.maximum用法及代碼示例
- Python tf.sparse.bincount用法及代碼示例
- Python tf.sparse.concat用法及代碼示例
- Python tf.sparse.transpose用法及代碼示例
- Python tf.sparse.softmax用法及代碼示例
- Python tf.sparse.to_indicator用法及代碼示例
- Python tf.sparse.from_dense用法及代碼示例
- Python tf.sparse.minimum用法及代碼示例
- Python tf.sparse.segment_sum用法及代碼示例
- Python tf.sparse.fill_empty_rows用法及代碼示例
- Python tf.sparse.slice用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.sparse.reduce_max。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。