aesara.tensor.stacklists#
- aesara.tensor.stacklists(arg)[source]#
Recursively stack lists of tensors to maintain similar structure.
This function can create a tensor from a shaped list of scalars:
Examples
>>> from aesara.tensor import stacklists >>> from aesara.tensor.type import scalars, matrices >>> from aesara import function >>> a, b, c, d = scalars('abcd') >>> X = stacklists([[a, b], [c, d]]) >>> f = function([a, b, c, d], X) >>> f(1, 2, 3, 4) array([[ 1., 2.], [ 3., 4.]], dtype=float32)
We can also stack arbitrarily shaped tensors. Here we stack matrices into a 2 by 2 grid:
>>> from numpy import ones >>> a, b, c, d = matrices('abcd') >>> X = stacklists([[a, b], [c, d]]) >>> f = function([a, b, c, d], X) >>> x = ones((4, 4), 'float32') >>> f(x, x, x, x).shape (2, 2, 4, 4)