| View source on GitHub | 
Retains specified non-empty values within a SparseTensor.
tf.sparse.retain(
    sp_input, to_retain
)
  For example, if sp_input has shape [4, 5] and 4 non-empty string values:
[0, 1]: a [0, 3]: b [2, 0]: c [3, 1]: d
and to_retain = [True, False, False, True], then the output will be a SparseTensor of shape [4, 5] with 2 non-empty values:
[0, 1]: a [3, 1]: d
| Args | |
|---|---|
| sp_input | The input SparseTensorwithNnon-empty elements. | 
| to_retain | A bool vector of length NwithMtrue values. | 
| Returns | |
|---|---|
| A SparseTensorwith the same shape as the input andMnon-empty elements corresponding to the true positions into_retain. | 
| Raises | |
|---|---|
| TypeError | If sp_inputis not aSparseTensor. | 
    © 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
    https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/sparse/retain