tf.sparse.maximum
Stay organized with collections
Save and categorize content based on your preferences.
Returns the element-wise max of two SparseTensors.
tf.sparse.maximum(
sp_a, sp_b, name=None
)
Assumes the two SparseTensors have the same shape, i.e., no broadcasting.
Example |
>>> sp_zero = tf.sparse.SparseTensor([[0]], [0], [7])
>>> sp_one = tf.sparse.SparseTensor([[1]], [1], [7])
>>> res = tf.sparse.maximum(sp_zero, sp_one)
>>> res.indices
<tf.Tensor: shape=(2, 1), dtype=int64, numpy=
array([[0],
[1]])>
>>> res.values
<tf.Tensor: shape=(2,), dtype=int32, numpy=array([0, 1], dtype=int32)>
>>> res.dense_shape
<tf.Tensor: shape=(1,), dtype=int64, numpy=array([7])>
|
The reduction version of this elementwise operation is tf.sparse.reduce_max
Args |
sp_a
|
a SparseTensor operand whose dtype is real, and indices
lexicographically ordered.
|
sp_b
|
the other SparseTensor operand with the same requirements (and the
same shape).
|
name
|
optional name of the operation.
|
Returns |
output
|
the output SparseTensor.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.sparse.maximum\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/sparse_ops.py#L2734-L2777) |\n\nReturns the element-wise max of two SparseTensors.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.sparse.maximum`](https://www.tensorflow.org/api_docs/python/tf/sparse/maximum), [`tf.compat.v1.sparse_maximum`](https://www.tensorflow.org/api_docs/python/tf/sparse/maximum)\n\n\u003cbr /\u003e\n\n tf.sparse.maximum(\n sp_a, sp_b, name=None\n )\n\nAssumes the two SparseTensors have the same shape, i.e., no broadcasting.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Example ------- ||\n|---|---|\n| \u003cbr /\u003e \u003e\u003e\u003e sp_zero = tf.sparse.SparseTensor([[0]], [0], [7]) \u003e\u003e\u003e sp_one = tf.sparse.SparseTensor([[1]], [1], [7]) \u003e\u003e\u003e res = tf.sparse.maximum(sp_zero, sp_one) \u003e\u003e\u003e res.indices \u003ctf.Tensor: shape=(2, 1), dtype=int64, numpy= array([[0], [1]])\u003e \u003e\u003e\u003e res.values \u003ctf.Tensor: shape=(2,), dtype=int32, numpy=array([0, 1], dtype=int32)\u003e \u003e\u003e\u003e res.dense_shape \u003ctf.Tensor: shape=(1,), dtype=int64, numpy=array([7])\u003e \u003cbr /\u003e ||\n\n\u003cbr /\u003e\n\nThe reduction version of this elementwise operation is [`tf.sparse.reduce_max`](../../tf/sparse/reduce_max)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|--------------------------------------------------------------------------------------|\n| `sp_a` | a `SparseTensor` operand whose dtype is real, and indices lexicographically ordered. |\n| `sp_b` | the other `SparseTensor` operand with the same requirements (and the same shape). |\n| `name` | optional name of the operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|----------|--------------------------|\n| `output` | the output SparseTensor. |\n\n\u003cbr /\u003e"]]