xbuilder

Defined in xtensor/xbuilder.hpp

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

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>
inline auto xt::ones(const I (&shape)[L]) noexcept
template<class T, class S>
inline auto xt::zeros(S shape) noexcept

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>
inline auto xt::zeros(const I (&shape)[L]) noexcept
template<class T, layout_type L = ::xt::layout_type::row_major, class S>
inline xarray<T, L> xt::empty(const S &shape)

Create a xcontainer (xarray, xtensor or xtensor_fixed) with uninitialized values of with value_type T and shape.

Selects the best container match automatically from the supplied shape.

  • std::vectorxarray<T>

  • std::array or initializer_listxtensor<T, N>

  • xshape<N...>xtensor_fixed<T, xshape<N...>>

Parameters

shape – shape of the new xcontainer

Warning

doxygenfunction: Unable to resolve function “xt::full_like” with arguments (const xexpression<E>&) in doxygen xml output for project “xtensor” from directory: ../xml. Potential matches:

- template<class E> auto full_like(const xexpression<E> &e, typename E::value_type fill_value)
template<class E>
inline auto xt::empty_like(const xexpression<E> &e)

Create a xcontainer (xarray, xtensor or xtensor_fixed) with uninitialized values of the same shape, value type and layout as the input xexpression e.

Parameters

e – the xexpression from which to extract shape, value type and layout.

template<class E>
inline auto xt::zeros_like(const xexpression<E> &e)

Create a xcontainer (xarray, xtensor or xtensor_fixed), filled with zeros and of the same shape, value type and layout as the input xexpression e.

Note: contrary to zeros(shape), this function returns a non-lazy, allocated container! Use `xt::zeros<double>(e.shape()); for a lazy version.

Parameters

e – the xexpression from which to extract shape, value type and layout.

template<class E>
inline auto xt::ones_like(const xexpression<E> &e)

Create a xcontainer (xarray, xtensor or xtensor_fixed), filled with ones and of the same shape, value type and layout as the input xexpression e.

Note: contrary to ones(shape), this function returns a non-lazy, evaluated container! Use xt::ones<double>(e.shape()); for a lazy version.

Parameters

e – the xexpression from which to extract shape, value type and layout.

template<class T = bool>
inline auto xt::eye(const std::vector<std::size_t> &shape, int k = 0)

Generates an array with ones on the diagonal.

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

Returns

xgenerator that generates the values on access

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

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

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

Returns

xgenerator that generates the values on access

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

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

Parameters
  • start – start of the interval

  • stop – stop of the interval

  • step – stepsize

Template Parameters

T – value_type of xexpression

Returns

xgenerator that generates the values on access

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

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

Parameters

stop – stop of the interval

Template Parameters

T – value_type of xexpression

Returns

xgenerator that generates the values on access

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

Generates num_samples evenly spaced numbers over given interval.

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

Returns

xgenerator that generates the values on access

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

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

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

Returns

xgenerator that generates the values on access

template<class ...CT>
inline auto xt::concatenate(std::tuple<CT...> &&t, std::size_t axis = 0)

Concatenates xexpressions along axis.

xt::xarray<double> a = {{1, 2, 3}};
xt::xarray<double> b = {{2, 3, 4}};
xt::xarray<double> c = xt::concatenate(xt::xtuple(a, b)); // => {{1, 2, 3},
                                                          //     {2, 3, 4}}
xt::xarray<double> d = xt::concatenate(xt::xtuple(a, b), 1); // => {{1, 2, 3, 2, 3, 4}}

Parameters
  • t – xtuple of xexpressions to concatenate

  • axis – axis along which elements are concatenated

Returns

xgenerator evaluating to concatenated elements

template<class ...CT>
inline auto xt::stack(std::tuple<CT...> &&t, std::size_t axis = 0)

Stack xexpressions along axis.

Stacking always creates a new dimension along which elements are stacked.

xt::xarray<double> a = {1, 2, 3};
xt::xarray<double> b = {5, 6, 7};
xt::xarray<double> s = xt::stack(xt::xtuple(a, b)); // => {{1, 2, 3},
                                                    //     {5, 6, 7}}
xt::xarray<double> t = xt::stack(xt::xtuple(a, b), 1); // => {{1, 5},
                                                       //     {2, 6},
                                                       //     {3, 7}}

Parameters
  • t – xtuple of xexpressions to concatenate

  • axis – axis along which elements are stacked

Returns

xgenerator evaluating to stacked elements

template<class ...CT>
inline auto xt::hstack(std::tuple<CT...> &&t)

Stack xexpressions in sequence horizontally (column wise).

This is equivalent to concatenation along the second axis, except for 1-D xexpressions where it concatenate along the firts axis.

Parameters

t – xtuple of xexpressions to stack

Returns

xgenerator evaluating to stacked elements

template<class ...CT>
inline auto xt::vstack(std::tuple<CT...> &&t)

Stack xexpressions in sequence vertically (row wise).

This is equivalent to concatenation along the first axis after 1-D arrays of shape (N) have been reshape to (1, N).

Parameters

t – xtuple of xexpressions to stack

Returns

xgenerator evaluating to stacked elements

template<class ...E>
inline auto xt::meshgrid(E&&... e) noexcept

Return coordinate tensors from coordinate vectors.

Make N-D coordinate tensor expressions for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays x1, x2,…, xn.

Parameters

e – xexpressions to concatenate

Returns

tuple of xgenerator expressions.

template<class E>
inline 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}}

Parameters
  • arr – the 1D input array of length n

  • k – the offset of the considered diagonal

Returns

xexpression function with shape n x n and arr on the diagonal

template<class E>
inline 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}

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.

Returns

xexpression with values of the diagonal

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

Extract lower triangular matrix from xexpression.

The parameter k selects the offset of the diagonal.

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.

Returns

xexpression containing lower triangle from arr, 0 otherwise

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

Extract upper triangular matrix from xexpression.

The parameter k selects the offset of the diagonal.

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.

Returns

xexpression containing lower triangle from arr, 0 otherwise