Tensor creation#

See also

Tensor creation

From shape or value#

empty(shape[, dtype])

Return a new array of given shape and type, without initializing entries.

empty_like(prototype[, dtype])

Return a new array with the same shape and type as a given array.

eye(n[, m, k, dtype])

Return a 2-D array with ones on the diagonal and zeros elsewhere.

ones(shape[, dtype])

Create a TensorVariable filled with ones, closer to NumPy's syntax than alloc.

ones_like(model[, dtype, opt])

Equivalent of numpy.ones_like.

zeros(shape[, dtype])

Create a TensorVariable filled with zeros, closer to NumPy's syntax than alloc.

zeros_like(model[, dtype, opt])

Equivalent of numpy.zeros_like.

full(shape, fill_value[, dtype])

Return a new array of given shape and type, filled with fill_value.

full_like(a, fill_value[, dtype])

Equivalent of numpy.full_like.

fill

Create a matrix by filling the shape of a with b Generalizes a scalar Op to tensors.

identity_like(x[, dtype])

Create a tensor with ones on main diagonal and zeroes elsewhere.

alloc

Create a TensorVariable from an initial value and a desired shape.

second

Create a matrix by filling the shape of a with b Generalizes a scalar Op to tensors.

From existing data#

as_tensor(x[, name, ndim])

Convert x into an equivalent TensorVariable.

Numerical ranges#

arange(start[, stop, step, dtype])

linspace(start, end, steps)

logspace(start, end, steps[, base])

geomspace(start, end, steps[, base])

mgrid

Create a dense n-dimensional 'meshgrid' with equally spaced points.

ogrid

Create a dense n-dimensional 'meshgrid' with equally spaced points.

aesara.tensor.mgrid()[source]#
Returns:

an instance which returns a dense (or fleshed out) mesh-grid when indexed, so that each returned argument has the same shape. The dimensions and number of the output arrays are equal to the number of indexing dimensions. If the step length is not a complex number, then the stop is not inclusive.

Example:

>>> a = at.mgrid[0:5, 0:3]
>>> a[0].eval()
array([[0, 0, 0],
       [1, 1, 1],
       [2, 2, 2],
       [3, 3, 3],
       [4, 4, 4]])
>>> a[1].eval()
array([[0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2],
       [0, 1, 2]])
aesara.tensor.ogrid()[source]#
Returns:

an instance which returns an open (i.e. not fleshed out) mesh-grid when indexed, so that only one dimension of each returned array is greater than 1. The dimension and number of the output arrays are equal to the number of indexing dimensions. If the step length is not a complex number, then the stop is not inclusive.

Example:

>>> b = at.ogrid[0:5, 0:3]
>>> b[0].eval()
array([[0],
       [1],
       [2],
       [3],
       [4]])
>>> b[1].eval()
array([[0, 1, 2]])

Building matrices#

diag(v[, k])

A helper function for two ops: ExtractDiag and AllocDiag.

tri(N[, M, k, dtype])

An array with ones at and below the given diagonal and zeros elsewhere.

tril(m[, k])

Lower triangle of an array.

triu(m[, k])

Upper triangle of an array.