Expression builders
xtensor provides functions to ease the build of common N-dimensional expressions. The expressions returned by these functions implement the laziness of xtensor, that is, they don’t hold any value. Values are computed upon request.
Ones and zeros
xt::zeros(shape): generates an expression containing zeros of the specified shape.xt::ones(shape): generates an expression containing ones of the specified shape.xt::eye(shape, k=0): generates an expression of the specified shape, with ones on the k-th diagonal.xt::eye(n, k = 0): generates an expression of shape(n, n)with ones on the k-th diagonal.
Numerical ranges
xt::arange(start=0, stop, step=1): generates numbers evenly spaced within given half-open interval.xt::linspace(start, stop, num_samples): generates num_samples evenly spaced numbers over given interval.xt::logspace(start, stop, num_samples): generates num_samples evenly spaced on a log scale over given interval
Joining expressions
xt::concatenate(tuple, axis=0): concatenates a list of expressions along the given axis.xt::stack(tuple, axis=0): stacks a list of expressions along the given axis.xt::hstack(tuple): stacks expressions in sequence horizontally (i.e. column-wise).xt::vstack(tuple): stacks expressions in sequence vertically (i.e. row wise).
Random distributions
Warning
xtensor uses a lazy generator for random numbers.
You need to assign them or use xt::eval() to keep the generated values consistent.
xt::random::rand(shape, lower, upper): generates an expression of the specified shape, containing uniformly distributed random numbers in the half-open interval [lower, upper).xt::random::randint(shape, lower, upper): generates an expression of the specified shape, containing uniformly distributed random integers in the half-open interval [lower, upper).xt::random::randn(shape, mean, std_dev): generates an expression of the specified shape, containing numbers sampled from the Normal random number distribution.xt::random::binomial(shape, trials, prob): generates an expression of the specified shape, containing numbers sampled from the binomial random number distribution.xt::random::geometric(shape, prob): generates an expression of the specified shape, containing numbers sampled from the geometric random number distribution.xt::random::negative_binomial(shape, k, prob): generates an expression of the specified shape, containing numbers sampled from the negative binomial random number distribution.xt::random::poisson(shape, rate): generates an expression of the specified shape, containing numbers sampled from the Poisson random number distribution.xt::random::exponential(shape, rate): generates an expression of the specified shape, containing numbers sampled from the exponential random number distribution.xt::random::gamma(shape, alpha, beta): generates an expression of the specified shape, containing numbers sampled from the gamma random number distribution.xt::random::weibull(shape, a, b): generates an expression of the specified shape, containing numbers sampled from the Weibull random number distribution.xt::random::extreme_value(shape, a, b): generates an expression of the specified shape, containing numbers sampled from the extreme value random number distribution.xt::random::lognormal(shape, a, b): generates an expression of the specified shape, containing numbers sampled from the Log-Normal random number distribution.xt::random::chi_squared(shape, a, b): generates an expression of the specified shape, containing numbers sampled from the chi-squared random number distribution.xt::random::cauchy(shape, a, b): generates an expression of the specified shape, containing numbers sampled from the Cauchy random number distribution.xt::random::fisher_f(shape, m, n): generates an expression of the specified shape, containing numbers sampled from the Fisher-f random number distribution.xt::random::student_t(shape, n): generates an expression of the specified shape, containing numbers sampled from the Student-t random number distribution.
Meshes
xt::meshgrid(x1, x2,...): generates N-D coordinate expressions given one-dimensional coordinate arraysx1,x2… If specified vectors have lengthsNi = len(xi), meshgrid returns(N1, N2, N3,..., Nn)-shaped arrays, with the elements of xi repeated to fill the matrix along the first dimension for x1, the second for x2 and so on.