aesara.tensor.stack#
- aesara.tensor.stack(*tensors, **kwargs)[source]#
Stack tensors in sequence on given axis (default is 0).
Take a sequence of tensors and stack them on given axis to make a single tensor. The size in dimension
axis
of the result will be equal to the number of tensors passed.Note: The interface stack(*tensors) is deprecated, you should use stack(tensors, axis=0) instead.
- Parameters:
tensors (list or tuple of tensors) – A list of tensors to be stacked.
axis (int) – The index of the new axis. Default value is 0.
Examples
>>> a = aesara.tensor.type.scalar() >>> b = aesara.tensor.type.scalar() >>> c = aesara.tensor.type.scalar() >>> x = aesara.tensor.stack([a, b, c]) >>> x.ndim # x is a vector of length 3. 1 >>> a = aesara.tensor.type.tensor4() >>> b = aesara.tensor.type.tensor4() >>> c = aesara.tensor.type.tensor4() >>> x = aesara.tensor.stack([a, b, c]) >>> x.ndim # x is a 5d tensor. 5 >>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c])) >>> rval.shape # 3 tensors are stacked on axis 0 (3, 2, 2, 2, 2) >>> x = aesara.tensor.stack([a, b, c], axis=3) >>> x.ndim 5 >>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c])) >>> rval.shape # 3 tensors are stacked on axis 3 (2, 2, 2, 3, 2) >>> x = aesara.tensor.stack([a, b, c], axis=-2) >>> x.ndim 5 >>> rval = x.eval(dict((t, np.zeros((2, 2, 2, 2))) for t in [a, b, c])) >>> rval.shape # 3 tensors are stacked on axis -2 (2, 2, 2, 3, 2)