View source on GitHub
|
Stacks a list of rank-R tensors into one rank-(R+1) tensor.
tf.stack(
values, axis=0, name='stack'
)
| Used in the guide | Used in the tutorials |
|---|---|
See also tf.concat, tf.tile, tf.repeat.
Packs the list of tensors in values into a tensor with rank one higher than
each tensor in values, by packing them along the axis dimension.
Given a list of length N of tensors of shape (A, B, C);
if axis == 0 then the output tensor will have the shape (N, A, B, C).
if axis == 1 then the output tensor will have the shape (A, N, B, C).
Etc.
x = tf.constant([1, 4])y = tf.constant([2, 5])z = tf.constant([3, 6])tf.stack([x, y, z])<tf.Tensor: shape=(3, 2), dtype=int32, numpy=array([[1, 4],[2, 5],[3, 6]], dtype=int32)>tf.stack([x, y, z], axis=1)<tf.Tensor: shape=(2, 3), dtype=int32, numpy=array([[1, 2, 3],[4, 5, 6]], dtype=int32)>
This is the opposite of unstack. The numpy equivalent is np.stack
np.array_equal(np.stack([x, y, z]), tf.stack([x, y, z]))True
values
Tensor objects with the same shape and type.
axis
int. The axis to stack along. Defaults to the first dimension.
Negative values wrap around, so the valid range is [-(R+1), R+1).
name
output
Tensor with the same type as values.
ValueError
axis is out of the range [-(R+1), R+1).
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.