Stacks a list of rank-R tensors into one rank-(R+1) tensor.
Aliases:
tf.compat.v1.stacktf.compat.v2.stack
tf.stack(
values,
axis=0,
name='stack'
)
Used in the guide:
TheKerasfunctionalAPIinTensorFlow``tf.data:BuildTensorFlowinputpipelines
Used in the tutorials:
Customtraining:walkthrough``LoadCSVdataLoadapandas.DataFramePix2PixPacks the list of tensors invaluesinto a tensor with rank one higher than each tensor invalues, by packing them along theaxisdimension. Given a list of lengthNof tensors of shape (A, B, C); ifaxis == 0then theoutputtensor will have the shape (N, A, B, CN, A, B, C). ifaxis == 1then theoutputtensor will have the shape (``). Etc.
For example:
x = tf.constant([1, 4])
y = tf.constant([2, 5])
z = tf.constant([3, 6])
tf.stack([x, y, z]) # [[1, 4], [2, 5], [3, 6]] (Pack along first dim.)
tf.stack([x, y, z], axis=1) # [[1, 2, 3], [4, 5, 6]]
This is the opposite of unstack. The numpy equivalent is
tf.stack([x, y, z]) = np.stack([x, y, z])
Args:
values: A list ofTensorobjects with the same shape and type.
Returns:
output: A stackedTensorwith the same type asvalues.
Raises:
ValueError: Ifaxisis out of the range [-(R+1), R+1).