tf.sparse.cross
Stay organized with collections
Save and categorize content based on your preferences.
Generates sparse cross from a list of sparse and dense tensors.
tf.sparse.cross(
inputs, name=None, separator=None
)
For example, if the inputs are
* inputs[0]: SparseTensor with shape = [2, 2]
[0, 0]: "a"
[1, 0]: "b"
[1, 1]: "c"
* inputs[1]: SparseTensor with shape = [2, 1]
[0, 0]: "d"
[1, 0]: "e"
* inputs[2]: Tensor [["f"], ["g"]]
then the output will be:
shape = [2, 2]
[0, 0]: "a_X_d_X_f"
[1, 0]: "b_X_e_X_g"
[1, 1]: "c_X_e_X_g"
Customized separator "Y":
inp_0 = tf.constant([['a'], ['b']])
inp_1 = tf.constant([['c'], ['d']])
output = tf.sparse.cross([inp_0, inp_1], separator='_Y_')
output.values
<tf.Tensor: shape=(2,), dtype=string, numpy=array([b'a_Y_c', b'b_Y_d'],
dtype=object)>
Args |
inputs
|
An iterable of Tensor or SparseTensor .
|
name
|
Optional name for the op.
|
separator
|
A string added between each string being joined. Defaults to
'X'.
|
Returns |
A SparseTensor of type string .
|
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. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.sparse.cross\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/sparse_ops.py#L608-L660) |\n\nGenerates sparse cross from a list of sparse and dense tensors.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.sparse.cross`](https://www.tensorflow.org/api_docs/python/tf/sparse/cross)\n\n\u003cbr /\u003e\n\n tf.sparse.cross(\n inputs, name=None, separator=None\n )\n\nFor example, if the inputs are \n\n * inputs[0]: SparseTensor with shape = [2, 2]\n [0, 0]: \"a\"\n [1, 0]: \"b\"\n [1, 1]: \"c\"\n * inputs[1]: SparseTensor with shape = [2, 1]\n [0, 0]: \"d\"\n [1, 0]: \"e\"\n * inputs[2]: Tensor [[\"f\"], [\"g\"]]\n\nthen the output will be: \n\n shape = [2, 2]\n [0, 0]: \"a_X_d_X_f\"\n [1, 0]: \"b_X_e_X_g\"\n [1, 1]: \"c_X_e_X_g\"\n\nCustomized separator \"*Y*\": \n\n inp_0 = tf.constant([['a'], ['b']])\n inp_1 = tf.constant([['c'], ['d']])\n output = tf.sparse.cross([inp_0, inp_1], separator='_Y_')\n output.values\n \u003ctf.Tensor: shape=(2,), dtype=string, numpy=array([b'a_Y_c', b'b_Y_d'],\n dtype=object)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|---------------------------------------------------------------------|\n| `inputs` | An iterable of `Tensor` or `SparseTensor`. |\n| `name` | Optional name for the op. |\n| `separator` | A string added between each string being joined. Defaults to '*X*'. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `SparseTensor` of type `string`. ||\n\n\u003cbr /\u003e"]]