Warning: This API is deprecated and will be removed in a future
version of TensorFlow after
the replacement is stable.
UniqueWithCounts
Stay organized with collections
Save and categorize content based on your preferences.
Finds unique elements along an axis of a tensor.
This operation either returns a tensor `y` containing unique elements
along the `axis` of a tensor. The returned unique elements is sorted
in the same order as they occur along `axis` in `x`.
This operation also returns a tensor `idx` and a tensor `count`
that are the same size as the number of the elements in `x` along the
`axis` dimension. The `idx` contains the index in the unique output `y`
and the `count` contains the count in the unique output `y`.
In other words, for an `1-D` tensor `x` with `axis = None:
`y[idx[i]] = x[i] for i in [0, 1,...,rank(x) - 1]`
For example:
x = tf.constant([1, 1, 2, 4, 4, 4, 7, 8, 8])
y, idx, count = tf.raw_ops.UniqueWithCountsV2(x=x, axis = [0])
y ==> [1, 2, 4, 7, 8]
idx ==> [0, 0, 1, 2, 2, 2, 3, 4, 4]
count ==> [2, 1, 3, 1, 2]
For a `2-D` tensor `x` with `axis = 0`:
x = tf.constant([[1, 0, 0],
[1, 0, 0],
[2, 0, 0]])
y, idx, count = tf.raw_ops.UniqueWithCountsV2(x=x, axis=[0])
y ==> [[1, 0, 0],
[2, 0, 0]]
idx ==> [0, 0, 1]
count ==> [2, 1]
For a `2-D` tensor `x` with `axis = 1`:
x = tf.constant([[1, 0, 0],
[1, 0, 0],
[2, 0, 0]])
y, idx, count = tf.raw_ops.UniqueWithCountsV2(x=x, axis=[1])
y ==> [[1, 0],
[1, 0],
[2, 0]]
idx ==> [0, 1, 1]
count ==> [1, 2]
Public Methods
Output<V>
|
|
static
<T, V extends Number, U extends Number>
UniqueWithCounts<T, V>
|
create( Scope scope, Operand<T> x, Operand<U> axis, Class<V> outIdx)
Factory method to create a class wrapping a new UniqueWithCounts operation.
|
static
<T, U extends Number>
UniqueWithCounts<T, Integer>
|
create( Scope scope, Operand<T> x, Operand<U> axis)
Factory method to create a class wrapping a new UniqueWithCounts operation using default output types.
|
Output<V>
|
|
Output<T>
|
|
Inherited Methods
From class
java.lang.Object
boolean
|
equals(Object arg0)
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
Public Methods
public
Output<V>
count
()
A 1-D Tensor. The count of each value of x in the output y.
Factory method to create a class wrapping a new UniqueWithCounts operation.
Parameters
scope |
current scope |
x |
A `Tensor`. |
axis |
A `Tensor` of type `int32` (default: None). The axis of the Tensor to
find the unique elements. |
Returns
- a new instance of UniqueWithCounts
Factory method to create a class wrapping a new UniqueWithCounts operation using default output types.
Parameters
scope |
current scope |
x |
A `Tensor`. |
axis |
A `Tensor` of type `int32` (default: None). The axis of the Tensor to
find the unique elements. |
Returns
- a new instance of UniqueWithCounts
public
Output<V>
idx
()
A 1-D Tensor. Has the same type as x that contains the index of each
value of x in the output y.
public
Output<T>
y
()
A `Tensor`. Unique elements along the `axis` of `Tensor` x.
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.
Last updated 2023-03-23 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-03-23 UTC."],[],[],null,["# UniqueWithCounts\n\npublic final class **UniqueWithCounts** \nFinds unique elements along an axis of a tensor.\n\n\nThis operation either returns a tensor \\`y\\` containing unique elements\nalong the \\`axis\\` of a tensor. The returned unique elements is sorted\nin the same order as they occur along \\`axis\\` in \\`x\\`.\nThis operation also returns a tensor \\`idx\\` and a tensor \\`count\\`\nthat are the same size as the number of the elements in \\`x\\` along the\n\\`axis\\` dimension. The \\`idx\\` contains the index in the unique output \\`y\\`\nand the \\`count\\` contains the count in the unique output \\`y\\`.\nIn other words, for an \\`1-D\\` tensor \\`x\\` with \\`axis = None:\n\n\n\\`y\\[idx\\[i\\]\\] = x\\[i\\] for i in \\[0, 1,...,rank(x) - 1\\]\\`\n\n\nFor example: \n\n x = tf.constant([1, 1, 2, 4, 4, 4, 7, 8, 8])\n y, idx, count = tf.raw_ops.UniqueWithCountsV2(x=x, axis = [0])\n y ==> [1, 2, 4, 7, 8]\n idx ==> [0, 0, 1, 2, 2, 2, 3, 4, 4]\n count ==> [2, 1, 3, 1, 2]\n \nFor a \\`2-D\\` tensor \\`x\\` with \\`axis = 0\\`: \n\n x = tf.constant([[1, 0, 0],\n [1, 0, 0],\n [2, 0, 0]])\n y, idx, count = tf.raw_ops.UniqueWithCountsV2(x=x, axis=[0])\n y ==> [[1, 0, 0],\n [2, 0, 0]]\n idx ==> [0, 0, 1]\n count ==> [2, 1]\n \nFor a \\`2-D\\` tensor \\`x\\` with \\`axis = 1\\`: \n\n x = tf.constant([[1, 0, 0],\n [1, 0, 0],\n [2, 0, 0]])\n y, idx, count = tf.raw_ops.UniqueWithCountsV2(x=x, axis=[1])\n y ==> [[1, 0],\n [1, 0],\n [2, 0]]\n idx ==> [0, 1, 1]\n count ==> [1, 2]\n \n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Public Methods\n\n|-------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Output](/api_docs/java/org/tensorflow/Output)\\\u003cV\\\u003e | [count](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts#count())() A 1-D Tensor. |\n| static \\\u003cT, V extends Number, U extends Number\\\u003e [UniqueWithCounts](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts)\\\u003cT, V\\\u003e | [create](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts#create(org.tensorflow.op.Scope,%20org.tensorflow.Operand\u003cT\u003e,%20org.tensorflow.Operand\u003cU\u003e,%20java.lang.Class\u003cV\u003e))([Scope](/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e x, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cU\\\u003e axis, Class\\\u003cV\\\u003e outIdx) Factory method to create a class wrapping a new UniqueWithCounts operation. |\n| static \\\u003cT, U extends Number\\\u003e [UniqueWithCounts](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts)\\\u003cT, Integer\\\u003e | [create](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts#create(org.tensorflow.op.Scope,%20org.tensorflow.Operand\u003cT\u003e,%20org.tensorflow.Operand\u003cU\u003e))([Scope](/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e x, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cU\\\u003e axis) Factory method to create a class wrapping a new UniqueWithCounts operation using default output types. |\n| [Output](/api_docs/java/org/tensorflow/Output)\\\u003cV\\\u003e | [idx](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts#idx())() A 1-D Tensor. |\n| [Output](/api_docs/java/org/tensorflow/Output)\\\u003cT\\\u003e | [y](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts#y())() A \\`Tensor\\`. |\n\n### Inherited Methods\n\nFrom class [org.tensorflow.op.PrimitiveOp](/api_docs/java/org/tensorflow/op/PrimitiveOp) \n\n|------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|\n| final boolean | [equals](/api_docs/java/org/tensorflow/op/PrimitiveOp#equals(java.lang.Object))(Object obj) |\n| final int | [hashCode](/api_docs/java/org/tensorflow/op/PrimitiveOp#hashCode())() |\n| [Operation](/api_docs/java/org/tensorflow/Operation) | [op](/api_docs/java/org/tensorflow/op/PrimitiveOp#op())() Returns the underlying [Operation](/api_docs/java/org/tensorflow/Operation) |\n| final String | [toString](/api_docs/java/org/tensorflow/op/PrimitiveOp#toString())() |\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Methods\n--------------\n\n#### public [Output](/api_docs/java/org/tensorflow/Output)\\\u003cV\\\u003e\n**count**\n()\n\nA 1-D Tensor. The count of each value of x in the output y. \n\n#### public static [UniqueWithCounts](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts)\\\u003cT, V\\\u003e\n**create**\n([Scope](/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e x, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cU\\\u003e axis, Class\\\u003cV\\\u003e outIdx)\n\nFactory method to create a class wrapping a new UniqueWithCounts operation. \n\n##### Parameters\n\n| scope | current scope |\n| x | A \\`Tensor\\`. |\n| axis | A \\`Tensor\\` of type \\`int32\\` (default: None). The axis of the Tensor to find the unique elements. |\n|-------|-----------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- a new instance of UniqueWithCounts \n\n#### public static [UniqueWithCounts](/api_docs/java/org/tensorflow/op/core/UniqueWithCounts)\\\u003cT, Integer\\\u003e\n**create**\n([Scope](/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e x, [Operand](/api_docs/java/org/tensorflow/Operand)\\\u003cU\\\u003e axis)\n\nFactory method to create a class wrapping a new UniqueWithCounts operation using default output types. \n\n##### Parameters\n\n| scope | current scope |\n| x | A \\`Tensor\\`. |\n| axis | A \\`Tensor\\` of type \\`int32\\` (default: None). The axis of the Tensor to find the unique elements. |\n|-------|-----------------------------------------------------------------------------------------------------|\n\n##### Returns\n\n- a new instance of UniqueWithCounts \n\n#### public [Output](/api_docs/java/org/tensorflow/Output)\\\u003cV\\\u003e\n**idx**\n()\n\nA 1-D Tensor. Has the same type as x that contains the index of each\nvalue of x in the output y. \n\n#### public [Output](/api_docs/java/org/tensorflow/Output)\\\u003cT\\\u003e\n**y**\n()\n\nA \\`Tensor\\`. Unique elements along the \\`axis\\` of \\`Tensor\\` x."]]