tf.sparse.split
Stay organized with collections
Save and categorize content based on your preferences.
Split a SparseTensor
into num_split
tensors along axis
.
tf.sparse.split(
sp_input=None, num_split=None, axis=None, name=None
)
If the sp_input.dense_shape[axis]
is not an integer multiple of num_split
each slice starting from 0:shape[axis] % num_split
gets extra one
dimension. For example:
indices = [[0, 2], [0, 4], [0, 5], [1, 0], [1, 1]]
values = [1, 2, 3, 4, 5]
t = tf.sparse.SparseTensor(indices=indices, values=values,
dense_shape=[2, 7])
tf.sparse.to_dense(t)
<tf.Tensor: shape=(2, 7), dtype=int32, numpy=
array([[0, 0, 1, 0, 2, 3, 0],
[4, 5, 0, 0, 0, 0, 0]], dtype=int32)>
output = tf.sparse.split(sp_input=t, num_split=2, axis=1)
tf.sparse.to_dense(output[0])
<tf.Tensor: shape=(2, 4), dtype=int32, numpy=
array([[0, 0, 1, 0],
[4, 5, 0, 0]], dtype=int32)>
tf.sparse.to_dense(output[1])
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
array([[2, 3, 0],
[0, 0, 0]], dtype=int32)>
output = tf.sparse.split(sp_input=t, num_split=2, axis=0)
tf.sparse.to_dense(output[0])
<tf.Tensor: shape=(1, 7), dtype=int32, numpy=array([[0, 0, 1, 0, 2, 3, 0]],
dtype=int32)>
tf.sparse.to_dense(output[1])
<tf.Tensor: shape=(1, 7), dtype=int32, numpy=array([[4, 5, 0, 0, 0, 0, 0]],
dtype=int32)>
output = tf.sparse.split(sp_input=t, num_split=2, axis=-1)
tf.sparse.to_dense(output[0])
<tf.Tensor: shape=(2, 4), dtype=int32, numpy=
array([[0, 0, 1, 0],
[4, 5, 0, 0]], dtype=int32)>
tf.sparse.to_dense(output[1])
<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
array([[2, 3, 0],
[0, 0, 0]], dtype=int32)>
Args |
sp_input
|
The SparseTensor to split.
|
num_split
|
A Python integer. The number of ways to split.
|
axis
|
A 0-D int32 Tensor . The dimension along which to split. Must be in
range [-rank, rank), where rank is the number of dimensions in the input
SparseTensor .
|
name
|
A name for the operation (optional).
|
Returns |
num_split SparseTensor objects resulting from splitting value .
|
Raises |
TypeError
|
If sp_input is not a SparseTensor .
|
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.
[[["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 2024-04-26 UTC."],[],[],null,["# tf.sparse.split\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#L1067-L1133) |\n\nSplit a `SparseTensor` into `num_split` tensors along `axis`. \n\n tf.sparse.split(\n sp_input=None, num_split=None, axis=None, name=None\n )\n\nIf the `sp_input.dense_shape[axis]` is not an integer multiple of `num_split`\neach slice starting from 0:`shape[axis] % num_split` gets extra one\ndimension. For example: \n\n indices = [[0, 2], [0, 4], [0, 5], [1, 0], [1, 1]]\n values = [1, 2, 3, 4, 5]\n t = tf.sparse.SparseTensor(indices=indices, values=values,\n dense_shape=[2, 7])\n tf.sparse.to_dense(t)\n \u003ctf.Tensor: shape=(2, 7), dtype=int32, numpy=\n array([[0, 0, 1, 0, 2, 3, 0],\n [4, 5, 0, 0, 0, 0, 0]], dtype=int32)\u003e\n\n output = tf.sparse.split(sp_input=t, num_split=2, axis=1)\n tf.sparse.to_dense(output[0])\n \u003ctf.Tensor: shape=(2, 4), dtype=int32, numpy=\n array([[0, 0, 1, 0],\n [4, 5, 0, 0]], dtype=int32)\u003e\n tf.sparse.to_dense(output[1])\n \u003ctf.Tensor: shape=(2, 3), dtype=int32, numpy=\n array([[2, 3, 0],\n [0, 0, 0]], dtype=int32)\u003e\n\n output = tf.sparse.split(sp_input=t, num_split=2, axis=0)\n tf.sparse.to_dense(output[0])\n \u003ctf.Tensor: shape=(1, 7), dtype=int32, numpy=array([[0, 0, 1, 0, 2, 3, 0]],\n dtype=int32)\u003e\n tf.sparse.to_dense(output[1])\n \u003ctf.Tensor: shape=(1, 7), dtype=int32, numpy=array([[4, 5, 0, 0, 0, 0, 0]],\n dtype=int32)\u003e\n\n output = tf.sparse.split(sp_input=t, num_split=2, axis=-1)\n tf.sparse.to_dense(output[0])\n \u003ctf.Tensor: shape=(2, 4), dtype=int32, numpy=\n array([[0, 0, 1, 0],\n [4, 5, 0, 0]], dtype=int32)\u003e\n tf.sparse.to_dense(output[1])\n \u003ctf.Tensor: shape=(2, 3), dtype=int32, numpy=\n array([[2, 3, 0],\n [0, 0, 0]], dtype=int32)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `sp_input` | The `SparseTensor` to split. |\n| `num_split` | A Python integer. The number of ways to split. |\n| `axis` | A 0-D `int32` `Tensor`. The dimension along which to split. Must be in range \\[-rank, rank), where rank is the number of dimensions in the input `SparseTensor`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| `num_split` `SparseTensor` objects resulting from splitting `value`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|----------------------------------------|\n| `TypeError` | If `sp_input` is not a `SparseTensor`. |\n\n\u003cbr /\u003e"]]