Tensor objects#
A TensorVariable
represents a multidimensional container of items of the same type and shape. The number of dimensions and items in a tensor is defined by its shape, a tuple of N non-negative integers or None
values that specify the sizes of each dimension (when known). The type of items in the array is determined by its dtype
attribute.
Example
A 2-dimensional array of size 2x2 composed of integer elements:
>>> x = at.as_tensor([[2, 3], [3, 4]], "int8")
>>> x.type.ndim
2
>>> x.type.shape
(2, 2)
>>> x.type.dtype
'int8'
A matrix of unknown dimension size:
>>> import aesara.tensor as at
>>> x = at.matrix('x')
>>> x.type.ndim
2
>>> x.type.shape
(None, None)
>>> x.type.dtype
'float32'
Note that Aesara returns None
when the shape of the tensor is unknown.
Constructing tensor variables#
New tensors can be constructed using the routines defined in Tensor creation, or at a low-level by calling the TensorType
type:
>>> import aesara as at
>>> mytype = at.TensorType("int32", shape=(None, 3))
>>> x = mytype()
|
Symbolic |
Tensor attributes#
|
|
The rank of this tensor. |
|
The dtype of this tensor. |
Tensor methods#
A TensorVariable
has many methods which operate on the array and typically return a new TensorVariable
.
Shape manipulation#
|
Return a reshaped view/copy of this variable. |
|
Reorder the dimensions of this variable, optionally inserting broadcasted dimensions. |
|
Transpose this array. |
|
See |
|
Returns a view of this variable with |
See |
|
Remove broadcastable dimensions from the shape of an array. |
Item selection and manipulation#
|
|
|
See |
|
Construct an array from an index array and a set of arrays to choose from. |
|
See |
|
See |
|
Return selected slices only. |
|
|
|
See |
See |
|
|
|
Calculation#
|
See |
|
See |
|
|
|
|
|
|
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
|
|
See |
See |
|
|
See |
|
See |
Tensor methods#
Comparison#
Danger
The Python operators ==
and !=
do not work as a comparison operator in the usual sense in Aesara. Use eq()
and neq()
respectively instead.
|
Return self<value. |
|
Return self<=value. |
|
Return self>value. |
|
Return self>=value. |
Unary operations#
Arithmetic#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Matrix multiplication:
|
|
|
|
|
|
Numerical types#
A string indicating the numerical type of the ndarray
for which a
Variable
of this Type
represents.
The dtype
attribute of a TensorType
instance can be any of the
following strings.
dtype |
domain |
bits |
---|---|---|
|
signed integer |
8 |
|
signed integer |
16 |
|
signed integer |
32 |
|
signed integer |
64 |
|
unsigned integer |
8 |
|
unsigned integer |
16 |
|
unsigned integer |
32 |
|
unsigned integer |
64 |
|
floating point |
32 |
|
floating point |
64 |
|
complex |
64 (two float32) |
|
complex |
128 (two float64) |