Tensor manipulation#
Basic operation#
|
Return the shape of |
Get a tuple of symbolic shape values. |
Casting#
|
Symbolically cast |
Return real component of complex-valued tensor |
|
Return imaginary component of complex-valued tensor |
Updating elements#
Attention
Index assignment is not supported in Aesara. If you want to do the equivalent of a[5] = b
or a[5]+=b
you will need to use the set_subtensor
or inc_subtensor
operator respectively.
|
Return x with the given subtensor overwritten by y. |
|
Update the value of an indexed array by a given amount. |
|
Returns a copy of an array with all elements of the main diagonal set to a specified scalar value. |
Changing tensor shape#
Specific to Aesara
The specify_shape
operator is specific to Aesara.
|
|
|
Return a copy of the array collapsed into one dimension. |
|
Specify a fixed shape for a |
Transpose-like operations#
|
Move axes of a TensorVariable to new positions. |
|
Swap the axes of a tensor. |
|
Convenience function to roll TensorTypes along the given axis. |
|
Reorder the dimensions of x. |
Changing number of dimensions#
|
Convert inputs to arrays with at least |
|
Convert inputs to arrays with at least |
|
Convert inputs to arrays with at least |
|
Broadcast an array to a new shape. |
|
Broadcast any number of arrays against each other. |
|
Remove broadcastable (length 1) dimensions from the shape of an array. |
Joining tensors#
|
Convenience function to concatenate |
|
Stack tensors in sequence on given axis (default is 0). |
|
Recursively stack lists of tensors to maintain similar structure. |
|
Stack arrays in sequence horizontally (column wise). |
|
Stack arrays in sequence vertically (row wise). |
|
- aesara.tensor.stack(tensors, axis=0)[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.- Parameters:
tensors – a list or a tuple of one or more tensors of the same rank.
axis – the axis along which the tensors will be stacked. Default value is
0
.
- Returns:
A tensor such that
rval[0] == tensors[0]
,rval[1] == tensors[1]
, etc.
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)
We can also specify different axis than default value
0
:>>> 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)
- aesara.tensor.stack(*tensors)[source]
Warning
The interface
stack(*tensors)
is deprecated! Usestack(tensors, axis=0)
instead.Stack tensors in sequence vertically (row wise).
Take a sequence of tensors and stack them vertically to make a single tensor.
- param tensors:
one or more tensors of the same rank
- returns:
A tensor such that
rval[0] == tensors[0]
,rval[1] == tensors[1]
, etc.
>>> x0 = at.scalar() >>> x1 = at.scalar() >>> x2 = at.scalar() >>> x = at.stack(x0, x1, x2) >>> x.ndim # x is a vector of length 3. 1
- aesara.tensor.concatenate(tensor_list, axis=0)[source]#
- Parameters:
tensor_list (a list or tuple of Tensors that all have the same shape in the axes not specified by the
axis
argument.) – one or more Tensors to be concatenated together into one.axis (literal or symbolic integer) – Tensors will be joined along this axis, so they may have different
shape[axis]
>>> x0 = at.fmatrix() >>> x1 = at.ftensor3() >>> x2 = at.fvector() >>> x = at.concatenate([x0, x1[0], at.shape_padright(x2)], axis=1) >>> x.ndim 2
- aesara.tensor.stacklists(tensor_list)[source]#
- Parameters:
tensor_list (an iterable that contains either tensors or other iterables of the same type as
tensor_list
(in other words, this is a tree whose leaves are tensors).) – tensors to be stacked together.
Recursively stack lists of tensors to maintain similar structure.
This function can create a tensor from a shaped list of scalars:
>>> from aesara.tensor import stacklists, 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.]])
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)
Splitting tensors#
|
Tiling tensors#
|
Tile input array |
|
Repeat elements of an array. |
Adding and removing elements#
|
Find the unique elements of an array. |
Rearranging elements#
|
|
|
Return a copy of the array collapsed into one dimension. |
|
|
|
Computes the inverse of permutations. |
Padding tensors#
|
Reshape |
|
Reshape |
|
Reshape |