Sorts a tensor. Usage: ```python import tensorflow as tf a = [1, 10, 26.9, 2.8, 166.32, 62.3] b = tf.sort(a,axis=-1,direction='ASCENDING',name=None) c = tf.keras.backend.eval(b) # Here, c = [ 1. 2.8 10. 26.9 62.3 166.32] ``` Args: values: 1-D or higher numer
(values, axis=-1, direction='ASCENDING', name=None)
| 35 | |
| 36 | @tf_export('sort') |
| 37 | def sort(values, axis=-1, direction='ASCENDING', name=None): |
| 38 | """Sorts a tensor. |
| 39 | |
| 40 | Usage: |
| 41 | |
| 42 | ```python |
| 43 | import tensorflow as tf |
| 44 | a = [1, 10, 26.9, 2.8, 166.32, 62.3] |
| 45 | b = tf.sort(a,axis=-1,direction='ASCENDING',name=None) |
| 46 | c = tf.keras.backend.eval(b) |
| 47 | # Here, c = [ 1. 2.8 10. 26.9 62.3 166.32] |
| 48 | ``` |
| 49 | |
| 50 | Args: |
| 51 | values: 1-D or higher numeric `Tensor`. |
| 52 | axis: The axis along which to sort. The default is -1, which sorts the last |
| 53 | axis. |
| 54 | direction: The direction in which to sort the values (`'ASCENDING'` or |
| 55 | `'DESCENDING'`). |
| 56 | name: Optional name for the operation. |
| 57 | |
| 58 | Returns: |
| 59 | A `Tensor` with the same dtype and shape as `values`, with the elements |
| 60 | sorted along the given `axis`. |
| 61 | |
| 62 | Raises: |
| 63 | ValueError: If axis is not a constant scalar, or the direction is invalid. |
| 64 | """ |
| 65 | with framework_ops.name_scope(name, 'sort'): |
| 66 | return _sort_or_argsort(values, axis, direction, return_argsort=False) |
| 67 | |
| 68 | |
| 69 | @tf_export('argsort') |