# tff.analytics.data_processing.to_stacked_tensor

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

Encodes the \`tf.data.Dataset as stacked tensors.

    @tf.function
    tff.analytics.data_processing.to_stacked_tensor(
        ds: tf.data.Dataset
    ) -> tf.Tensor

This is effectively the inverse of [`tf.data.Dataset.from_tensor_slices()`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_tensor_slices).
All elements from the input dataset are concatenated into a tensor structure,
where the output structure matches the input `ds.element_spec`, and each
output tensor will have the same shape plus one additional prefix dimension
which elements are stacked in. For example, if the dataset contains 5
elements with shape \[3, 2\], the returned tensor will have shape \[5, 3, 2\].
Note that each element in the dataset could be as single tensor or a structure
of tensors.

Dataset elements must have fully-defined shapes. Any partially-defined element
shapes will raise an error. If passing in a batched dataset, use
`drop_remainder=True` to ensure the batched shape is fully defined.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `ds` | The input [`tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) to stack. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A structure of tensors encoding the input dataset. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If any dataset element shape is not fully-defined. |

<br />