xbuilder

Defined in xtensor/xbuilder.hpp

template <class T, class S>
auto xt::ones(S shape)

Returns an xexpression containing ones of the specified shape.

Template Parameters
  • shape: the shape of the returned expression.

template <class T, class I, std::size_t L>
auto xt::ones(const I (&shape)[L])
template <class T, class S>
auto xt::zeros(S shape)

Returns an xexpression containing zeros of the specified shape.

Template Parameters
  • shape: the shape of the returned expression.

template <class T, class I, std::size_t L>
auto xt::zeros(const I (&shape)[L])
template <class T = bool>
auto xt::eye(const std::vector<std::size_t> &shape, int k = 0)

Generates an array with ones on the diagonal.

Return
xgenerator that generates the values on access
Parameters
  • shape: shape of the resulting expression
  • k: index of the diagonal. 0 (default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.
Template Parameters
  • T: value_type of xexpression

template <class T = bool>
auto xt::eye(std::size_t n, int k = 0)

Generates a (n x n) array with ones on the diagonal.

Return
xgenerator that generates the values on access
Parameters
  • n: length of the diagonal.
  • k: index of the diagonal. 0 (default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.
Template Parameters
  • T: value_type of xexpression

template <class T>
auto xt::arange(T start, T stop, T step = 1)

Generates numbers evenly spaced within given half-open interval [start, stop).

Return
xgenerator that generates the values on access
Parameters
  • start: start of the interval
  • stop: stop of the interval
  • step: stepsize
Template Parameters
  • T: value_type of xexpression

template <class T>
auto xt::arange(T stop)

Generate numbers evenly spaced within given half-open interval [0, stop) with a step size of 1.

Return
xgenerator that generates the values on access
Parameters
  • stop: stop of the interval
Template Parameters
  • T: value_type of xexpression

template <class T>
auto xt::linspace(T start, T stop, std::size_t num_samples = 50, bool endpoint = true)

Generates num_samples evenly spaced numbers over given interval.

Return
xgenerator that generates the values on access
Parameters
  • start: start of interval
  • stop: stop of interval
  • num_samples: number of samples (defaults to 50)
  • endpoint: if true, include endpoint (defaults to true)
Template Parameters
  • T: value_type of xexpression

template <class T>
auto xt::logspace(T start, T stop, std::size_t num_samples, T base = 10, bool endpoint = true)

Generates num_samples numbers evenly spaced on a log scale over given interval.

Return
xgenerator that generates the values on access
Parameters
  • start: start of interval (pow(base, start) is the first value).
  • stop: stop of interval (pow(base, stop) is the final value, except if endpoint = false)
  • num_samples: number of samples (defaults to 50)
  • base: the base of the log space.
  • endpoint: if true, include endpoint (defaults to true)
Template Parameters
  • T: value_type of xexpression

template <class E>
auto xt::diag(E &&arr, int k = 0)

xexpression with values of arr on the diagonal, zeroes otherwise

xt::xarray<double> a = {1, 5, 9};
auto b = xt::diag(a); // => {{1, 0, 0},
                      //     {0, 5, 0},
                      //     {0, 0, 9}}
Return
xexpression function with shape n x n and arr on the diagonal
Parameters
  • arr: the 1D input array of length n
  • k: the offset of the considered diagonal

template <class E>
auto xt::diagonal(E &&arr, int offset = 0, std::size_t axis_1 = 0, std::size_t axis_2 = 1)

Returns the elements on the diagonal of arr If arr has more than two dimensions, then the axes specified by axis_1 and axis_2 are used to determine the 2-D sub-array whose diagonal is returned.

The shape of the resulting array can be determined by removing axis1 and axis2 and appending an index to the right equal to the size of the resulting diagonals.

xt::xarray<double> a = {{1, 2, 3},
                        {4, 5, 6}
                        {7, 8, 9}};
auto b = xt::diagonal(a); // => {1, 5, 9}
Return
xexpression with values of the diagonal
Parameters
  • arr: the input array
  • offset: offset of the diagonal from the main diagonal. Can be positive or negative.
  • axis_1: Axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken.
  • axis_2: Axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be taken.

template <class E>
auto xt::tril(E &&arr, int k = 0)

Extract lower triangular matrix from xexpression.

The parameter k selects the offset of the diagonal.

Return
xexpression containing lower triangle from arr, 0 otherwise
Parameters
  • arr: the input array
  • k: the diagonal above which to zero elements. 0 (default) selects the main diagonal, k < 0 is below the main diagonal, k > 0 above.

template <class E>
auto xt::triu(E &&arr, int k = 0)

Extract upper triangular matrix from xexpression.

The parameter k selects the offset of the diagonal.

Return
xexpression containing lower triangle from arr, 0 otherwise
Parameters
  • arr: the input array
  • k: the diagonal below which to zero elements. 0 (default) selects the main diagonal, k < 0 is below the main diagonal, k > 0 above.

template <class E>
auto xt::flip(E &&arr, std::size_t axis)

Reverse the order of elements in an xexpression along the given axis.

Note: A NumPy/Matlab style flipud(arr) is equivalent to xt::flip(arr, 0), fliplr(arr) to xt::flip(arr, 1).

Return
xexpression evaluating to reversed array
Parameters
  • arr: the input xexpression
  • axis: the axis along which elements should be reversed