UniqueWithCounts
tensorflow C++ API
tensorflow::ops::UniqueWithCounts
Finds unique elements in a 1-D tensor.
Summary
This operation returns a tensory
containing all of the unique elements ofx
sorted in the same order that they occur inx
. This operation also returns a tensoridx
the same size asx
that contains the index of each value ofx
in the unique outputy
. Finally, it returns a third tensorcount
that contains the count of each element ofy
inx
. In other words:
y[idx[i]] = x[i] for i in [0, 1,...,rank(x) - 1]
For example:
``` tensor 'x' is [1, 1, 2, 4, 4, 4, 7, 8, 8]
y, idx, count = unique_with_counts(x) y ==> [1, 2, 4, 7, 8] idx ==> [0, 0, 1, 2, 2, 2, 3, 4, 4] count ==> [2, 1, 3, 1, 2] ```
Arguments:
- scope: A Scope object
- x: 1-D.
Returns:
UniqueWithCounts block
Source link :https://github.com/EXPNUNI/enuSpaceTensorflow/blob/master/enuSpaceTensorflow/tf_array_ops.cpp
Argument:
- Scope scope : A Scope object (A scope is generated automatically each page. A scope is not connected.)
- Input x: A 1-D
Tensor
. - Unique::Attrs attrs:
- out_idx: An optional. Specifies the type of idx. from:
DT_INT32, DT_INT64
. Defaults toDT_INT32
.
- out_idx: An optional. Specifies the type of idx. from:
Output:
- Output y: Output object of UniqueWithCounts class object.
- Output idx: Output object of UniqueWithCounts class object.
- Output count: Output object of UniqueWithCounts class object.
Result:
- std::vector(Tensor)
result_y
: ATensor
. Has the same type asx
. 1-D. - std::vector(Tensor)
result_idx
: ATensor
of typeout_idx
. 1-D. - std::vector(Tensor)
result_count
: A 1-DTensor
. Check for duplicate values.
Using Method
※ Unique와 동일한 기능을 하고, 중복된 값이 각각 몇번 중복되었는지 count하는 기능이 추가되었다. 결과값 y는 유니크한 값을 모아놓은 tensor이고, idx는 x에서 각각의 해당하는 값이 y에서 몇 번째 index인지 알려주는 역할을 한다. attrs의 out_idx는 idx의 데이터 타입을 지정한다.