# TensorArray Operations

Note: Functions taking `Tensor`

arguments can also take anything accepted by
`tf.convert_to_tensor`

.

[TOC]

TensorArray operations.

## Classes containing dynamically sized arrays of Tensors.

`class tf.TensorArray`

Class wrapping dynamic-sized, per-time-step, write-once Tensor arrays.

This class is meant to be used with dynamic iteration primitives such as
`while_loop`

and `map_fn`

. It supports gradient back-propagation via special
"flow" control flow dependencies.

`tf.TensorArray.handle`

The reference to the TensorArray.

`tf.TensorArray.flow`

The flow `Tensor`

forcing ops leading to this TensorArray state.

`tf.TensorArray.read(index, name=None)`

Read the value at location `index`

in the TensorArray.

##### Args:

: 0-D. int32 tensor with the index to read from.`index`

: A name for the operation (optional).`name`

##### Returns:

The tensor at index `index`

.

`tf.TensorArray.gather(indices, name=None)`

Return selected values in the TensorArray as a packed `Tensor`

.

All of selected values must have been written and their shapes must all match.

##### Args:

: A`indices`

`1-D`

`Tensor`

taking values in`[0, max_value)`

. If the`TensorArray`

is not dynamic,`max_value=size()`

.: A name for the operation (optional).`name`

##### Returns:

The in the `TensorArray`

selected by `indices`

, packed into one tensor.

`tf.TensorArray.pack(name=None)`

Return the values in the TensorArray as a packed `Tensor`

.

All of the values must have been written and their shapes must all match.

##### Args:

: A name for the operation (optional).`name`

##### Returns:

All the tensors in the TensorArray packed into one tensor.

`tf.TensorArray.concat(name=None)`

Return the values in the TensorArray as a concatenated `Tensor`

.

All of the values must have been written, their ranks must match, and and their shapes must all match for all dimensions except the first.

##### Args:

: A name for the operation (optional).`name`

##### Returns:

All the tensors in the TensorArray concatenated into one tensor.

`tf.TensorArray.write(index, value, name=None)`

Write `value`

into index `index`

of the TensorArray.

##### Args:

: 0-D. int32 scalar with the index to write to.`index`

: N-D. Tensor of type`value`

`dtype`

. The Tensor to write to this index.: A name for the operation (optional).`name`

##### Returns:

A new TensorArray object with flow that ensures the write occurs. Use this object all for subsequent operations.

##### Raises:

: if there are more writers than specified.`ValueError`

`tf.TensorArray.scatter(indices, value, name=None)`

Scatter the values of a `Tensor`

in specific indices of a `TensorArray`

.

##### Args:

: A`indices`

`1-D`

`Tensor`

taking values in`[0, max_value)`

. If the`TensorArray`

is not dynamic,`max_value=size()`

.: (N+1)-D. Tensor of type`value`

`dtype`

. The Tensor to unpack.: A name for the operation (optional).`name`

##### Returns:

A new TensorArray object with flow that ensures the scatter occurs. Use this object all for subsequent operations.

##### Raises:

: if the shape inference fails.`ValueError`

`tf.TensorArray.unpack(value, name=None)`

Pack the values of a `Tensor`

in the TensorArray.

##### Args:

: (N+1)-D. Tensor of type`value`

`dtype`

. The Tensor to unpack.: A name for the operation (optional).`name`

##### Returns:

A new TensorArray object with flow that ensures the unpack occurs. Use this object all for subsequent operations.

##### Raises:

: if the shape inference fails.`ValueError`

`tf.TensorArray.split(value, lengths, name=None)`

Split the values of a `Tensor`

into the TensorArray.

##### Args:

: (N+1)-D. Tensor of type`value`

`dtype`

. The Tensor to split.: 1-D. int32 vector with the lengths to use when splitting`lengths`

`value`

along its first dimension.: A name for the operation (optional).`name`

##### Returns:

A new TensorArray object with flow that ensures the split occurs. Use this object all for subsequent operations.

##### Raises:

: if the shape inference fails.`ValueError`

`tf.TensorArray.grad(source, flow=None, name=None)`

#### Other Methods

`tf.TensorArray.__init__(dtype, size=None, dynamic_size=None, clear_after_read=None, tensor_array_name=None, handle=None, flow=None, infer_shape=True, name=None)`

Construct a new TensorArray or wrap an existing TensorArray handle.

A note about the parameter `name`

:

The name of the `TensorArray`

(even if passed in) is uniquified: each time
a new `TensorArray`

is created at runtime it is assigned its own name for
the duration of the run. This avoids name collisions if a `TensorArray`

is created within a `while_loop`

.

##### Args:

: (required) data type of the TensorArray.`dtype`

: (optional) int32 scalar`size`

`Tensor`

: the size of the TensorArray. Required if handle is not provided.: (optional) Python bool: If true, writes to the TensorArray can grow the TensorArray past its initial size. Default: False.`dynamic_size`

: Boolean (optional, default: True). If True, clear TensorArray values after reading them. This disables read-many semantics, but allows early release of memory.`clear_after_read`

: (optional) Python string: the name of the TensorArray. This is used when creating the TensorArray handle. If this value is set, handle should be None.`tensor_array_name`

: (optional) A`handle`

`Tensor`

handle to an existing TensorArray. If this is set, tensor_array_name should be None.: (optional) A float`flow`

`Tensor`

scalar coming from an existing`TensorArray.flow`

.: (optional, default: True) If True, shape inference is enabled. In this case, all elements must have the same shape.`infer_shape`

: A name for the operation (optional).`name`

##### Raises:

: if both handle and tensor_array_name are provided.`ValueError`

: if handle is provided but is not a Tensor.`TypeError`

`tf.TensorArray.close(name=None)`

Close the current TensorArray.

`tf.TensorArray.dtype`

The data type of this TensorArray.

`tf.TensorArray.size(name=None)`

Return the size of the TensorArray.