Stacks a list of rank-R
tensors into one rank-(R
+1) tensor.
Aliases:
tf.compat.v1.stack
tf.compat.v2.stack
tf.stack(
values,
axis=0,
name='stack'
)
Used in the guide:
T
he
K
er
as
f
un
ct
io
na
lA
P
Ii
n
T
en
so
rF
lo
w``t
f.
da
ta
:B
u
il
dT
e
ns
or
Fl
ow
i
np
ut
p
ip
el
in
es
Used in the tutorials:
C
us
to
mt
r
ai
ni
ng
:w
a
lk
th
ro
ug
h``L
oa
dC
S
Vd
a
ta
L
oa
da
p
a
nd
as
.D
at
aF
ra
me
P
ix
2P
ix
Packs the list of tensors invalues
into a tensor with rank one higher than each tensor invalues
, by packing them along theaxis
dimension. Given a list of lengthN
of tensors of shape (A, B, C
); ifaxis == 0
then theoutput
tensor will have the shape (N, A, B, CN, A, B, C
). ifaxis == 1
then theoutput
tensor 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 ofTensor
objects with the same shape and type.
Returns:
output
: A stackedTensor
with the same type asvalues
.
Raises:
ValueError
: Ifaxis
is out of the range [-(R+1), R+1).