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()

TensorType(dtype[, shape, name, broadcastable])

Symbolic Type representing numpy.ndarrays.

Tensor attributes#

TensorVariable.shape

TensorVariable.size

TensorVariable.name

TensorVariable.astype(dtype)

TensorVariable.ndim

The rank of this tensor.

TensorVariable.dtype

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#

TensorVariable.reshape(shape[, ndim])

Return a reshaped view/copy of this variable.

TensorVariable.dimshuffle(*pattern)

Reorder the dimensions of this variable, optionally inserting broadcasted dimensions.

TensorVariable.transpose(*axes)

Transpose this array.

TensorVariable.T

TensorVariable.swapaxes(axis1, axis2)

See aesara.tensor.basic.swapaxes.

TensorVariable.flatten([ndim])

Returns a view of this variable with ndim dimensions, whose shape for the first ndim-1 dimensions will be the same as self, and shape in the remaining dimension will be expanded to fit in all the data from self.

TensorVariable.ravel()

See flatten.

TensorVariable.squeeze()

Remove broadcastable dimensions from the shape of an array.

Item selection and manipulation#

TensorVariable.take(indices[, axis, mode])

TensorVariable.repeat(repeats[, axis])

See aesara.tensor.basic.repeat.

TensorVariable.choose(choices[, mode])

Construct an array from an index array and a set of arrays to choose from.

TensorVariable.sort([axis, kind, order])

See aesara.tensor.sort.sort.

TensorVariable.argsort([axis, kind, order])

See aesara.tensor.sort.argsort.

TensorVariable.compress(a[, axis])

Return selected slices only.

TensorVariable.searchsorted(v[, side, sorter])

TensorVariable.nonzero([return_matrix])

See aesara.tensor.basic.nonzero.

TensorVariable.nonzero_values()

See aesara.tensor.basic.nonzero_values.

TensorVariable.diagonal([offset, axis1, axis2])

TensorVariable.get_scalar_constant_value()

Calculation#

TensorVariable.sum([axis, dtype, keepdims, ...])

See aesara.tensor.math.sum.

TensorVariable.prod([axis, dtype, keepdims, ...])

See aesara.tensor.math.prod.

TensorVariable.cumsum([axis])

TensorVariable.cumprod([axis])

TensorVariable.norm(L[, axis, keepdims])

TensorVariable.mean([axis, dtype, keepdims, ...])

See aesara.tensor.math.mean.

TensorVariable.var([axis, ddof, keepdims, ...])

See aesara.tensor.math.var.

TensorVariable.std([axis, ddof, keepdims, ...])

See aesara.tensor.math.std.

TensorVariable.min([axis, keepdims])

See aesara.tensor.math.min.

TensorVariable.argmin([axis, keepdims])

See aesara.tensor.math.argmin.

TensorVariable.max([axis, keepdims])

See aesara.tensor.math.max.

TensorVariable.argmax([axis, keepdims])

See aesara.tensor.math.argmax.

TensorVariable.any([axis, keepdims])

TensorVariable.clip(a_min, a_max)

See aesara.tensor.math.clip.

TensorVariable.conjugate()

See aesara.tensor.math.conj.

TensorVariable.ptp([axis])

See aesara.tensor.math.ptp.

TensorVariable.trunc()

TensorVariable.round([mode])

See aesara.tensor.math.round.

TensorVariable.trace()

TensorVariable.arccos()

TensorVariable.arccosh()

TensorVariable.arcsin()

TensorVariable.arcsinh()

TensorVariable.arctan()

TensorVariable.arctanh()

TensorVariable.ceil()

TensorVariable.cos()

TensorVariable.cosh()

TensorVariable.deg2rad()

TensorVariable.exp()

TensorVariable.exp2()

TensorVariable.expm1()

TensorVariable.floor()

TensorVariable.log()

TensorVariable.log10()

TensorVariable.log1p()

TensorVariable.log2()

TensorVariable.rad2deg()

TensorVariable.sin()

TensorVariable.sinh()

TensorVariable.sqrt()

TensorVariable.tan()

TensorVariable.tanh()

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.

TensorVariable.__lt__(other)

Return self<value.

TensorVariable.__le__(other)

Return self<=value.

TensorVariable.__gt__(other)

Return self>value.

TensorVariable.__ge__(other)

Return self>=value.

Unary operations#

TensorVariable.__abs__()

TensorVariable.__neg__()

TensorVariable.__invert__()

Arithmetic#

TensorVariable.__add__(other)

TensorVariable.__radd__(other)

TensorVariable.__sub__(other)

TensorVariable.__mul__(other)

TensorVariable.__truediv__(other)

TensorVariable.__floordiv__(other)

TensorVariable.__rtruediv__(other)

TensorVariable.__rfloordiv__(other)

TensorVariable.__mod__(other)

TensorVariable.__rmod__(other)

TensorVariable.__divmod__(other)

TensorVariable.__rdivmod__(other)

TensorVariable.__pow__(other)

TensorVariable.__rpow__(other)

TensorVariable.__and__(other)

TensorVariable.__or__(other)

TensorVariable.__ror__(other)

TensorVariable.__xor__(other)

TensorVariable.__rxor__(other)

TensorVariable.__rand__(other)

TensorVariable.__rsub__(other)

TensorVariable.__rmul__(other)

TensorVariable.__div__(other)

TensorVariable.__rdiv__(other)

TensorVariable.__ceil__()

TensorVariable.__floor__()

TensorVariable.__trunc__()

Matrix multiplication:

TensorVariable.__dot__(right)

TensorVariable.__rdot__(left)

TensorVariable.__matmul__(right)

TensorVariable.__rmatmul__(left)

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

'int8'

signed integer

8

'int16'

signed integer

16

'int32'

signed integer

32

'int64'

signed integer

64

'uint8'

unsigned integer

8

'uint16'

unsigned integer

16

'uint32'

unsigned integer

32

'uint64'

unsigned integer

64

'float32'

floating point

32

'float64'

floating point

64

'complex64'

complex

64 (two float32)

'complex128'

complex

128 (two float64)