MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / argsort

Function argsort

tensorflow/python/ops/sort_ops.py:70–109  ·  view source on GitHub ↗

Returns the indices of a tensor that give its sorted order along an axis. For a 1D tensor, `tf.gather(values, tf.argsort(values))` is equivalent to `tf.sort(values)`. For higher dimensions, the output has the same shape as `values`, but along the given axis, values represent the index of the

(values, axis=-1, direction='ASCENDING', stable=False, name=None)

Source from the content-addressed store, hash-verified

68
69@tf_export('argsort')
70def argsort(values, axis=-1, direction='ASCENDING', stable=False, name=None):
71 """Returns the indices of a tensor that give its sorted order along an axis.
72
73 For a 1D tensor, `tf.gather(values, tf.argsort(values))` is equivalent to
74 `tf.sort(values)`. For higher dimensions, the output has the same shape as
75 `values`, but along the given axis, values represent the index of the sorted
76 element in that slice of the tensor at the given position.
77
78 Usage:
79
80 ```python
81 import tensorflow as tf
82 a = [1, 10, 26.9, 2.8, 166.32, 62.3]
83 b = tf.argsort(a,axis=-1,direction='ASCENDING',stable=False,name=None)
84 c = tf.keras.backend.eval(b)
85 # Here, c = [0 3 1 2 5 4]
86 ```
87
88 Args:
89 values: 1-D or higher numeric `Tensor`.
90 axis: The axis along which to sort. The default is -1, which sorts the last
91 axis.
92 direction: The direction in which to sort the values (`'ASCENDING'` or
93 `'DESCENDING'`).
94 stable: If True, equal elements in the original tensor will not be
95 re-ordered in the returned order. Unstable sort is not yet implemented,
96 but will eventually be the default for performance reasons. If you require
97 a stable order, pass `stable=True` for forwards compatibility.
98 name: Optional name for the operation.
99
100 Returns:
101 An int32 `Tensor` with the same shape as `values`. The indices that would
102 sort each slice of the given `values` along the given `axis`.
103
104 Raises:
105 ValueError: If axis is not a constant scalar, or the direction is invalid.
106 """
107 del stable # Unused.
108 with framework_ops.name_scope(name, 'argsort'):
109 return _sort_or_argsort(values, axis, direction, return_argsort=True)
110
111
112def _sort_or_argsort(values, axis, direction, return_argsort):

Callers

nothing calls this directly

Calls 2

_sort_or_argsortFunction · 0.85
name_scopeMethod · 0.45

Tested by

no test coverage detected