xtensor
Loading...
Searching...
No Matches
Xt_xmanipulation

Functions

template<class E >
auto xt::transpose (E &&e) noexcept
 Returns a transpose view by reversing the dimensions of xexpression e.
 
template<class E , class S , class Tag = check_policy::none>
auto xt::transpose (E &&e, S &&permutation, Tag check_policy)
 Returns a transpose view by permuting the xexpression e with permutation.
 
template<class E >
auto xt::swapaxes (E &&e, std::ptrdiff_t axis1, std::ptrdiff_t axis2)
 Return a new expression with two axes interchanged.
 
template<class E >
auto xt::moveaxis (E &&e, std::ptrdiff_t src, std::ptrdiff_t dest)
 Return a new expression with an axis move to a new position.
 
template<layout_type L = ::xt::layout_type::row_major, class E >
auto xt::ravel (E &&e)
 Return a flatten view of the given expression.
 
template<layout_type L = ::xt::layout_type::row_major, class E >
auto xt::flatten (E &&e)
 Return a flatten view of the given expression.
 
template<class E >
auto xt::trim_zeros (E &&e, const std::string &direction)
 Trim zeros at beginning, end or both of 1D sequence.
 
template<class E >
auto xt::squeeze (E &&e)
 Returns a squeeze view of the given expression.
 
template<class E , class S , class Tag = check_policy::none, std::enable_if_t<!xtl::is_integral< S >::value, int > = 0>
auto xt::squeeze (E &&e, S &&axis, Tag check_policy)
 Remove single-dimensional entries from the shape of an xexpression.
 
template<class E >
auto xt::expand_dims (E &&e, std::size_t axis)
 Expand the shape of an xexpression.
 
template<std::size_t N, class E >
auto xt::atleast_Nd (E &&e)
 Expand dimensions of xexpression to at least N
 
template<class E >
auto xt::atleast_1d (E &&e)
 Expand to at least 1D.
 
template<class E >
auto xt::atleast_2d (E &&e)
 Expand to at least 2D.
 
template<class E >
auto xt::atleast_3d (E &&e)
 Expand to at least 3D.
 
template<class E >
auto xt::split (E &e, std::size_t n, std::size_t axis)
 Split xexpression along axis into subexpressions.
 
template<class E >
auto xt::hsplit (E &e, std::size_t n)
 Split an xexpression into subexpressions horizontally (column-wise)
 
template<class E >
auto xt::vsplit (E &e, std::size_t n)
 Split an xexpression into subexpressions vertically (row-wise)
 
template<class E >
auto xt::flip (E &&e)
 Reverse the order of elements in an xexpression along every axis.
 
template<class E >
auto xt::flip (E &&e, std::size_t axis)
 Reverse the order of elements in an xexpression along the given axis.
 
template<std::ptrdiff_t N = 1, class E >
auto xt::rot90 (E &&e, const std::array< std::ptrdiff_t, 2 > &axes)
 Rotate an array by 90 degrees in the plane specified by axes.
 
template<class E >
auto xt::roll (E &&e, std::ptrdiff_t shift)
 Roll an expression.
 
template<class E >
auto xt::roll (E &&e, std::ptrdiff_t shift, std::ptrdiff_t axis)
 Roll an expression along a given axis.
 
template<class E >
auto xt::repeat (E &&e, std::size_t repeats, std::size_t axis)
 Repeat elements of an expression along a given axis.
 
template<class E >
auto xt::repeat (E &&e, const std::vector< std::size_t > &repeats, std::size_t axis)
 Repeat elements of an expression along a given axis.
 
template<class E >
auto xt::repeat (E &&e, std::vector< std::size_t > &&repeats, std::size_t axis)
 Repeat elements of an expression along a given axis.
 

Detailed Description

Function Documentation

◆ atleast_1d()

template<class E >
auto xt::atleast_1d ( E && e)
inline

Expand to at least 1D.

See also
atleast_Nd

Definition at line 685 of file xmanipulation.hpp.

◆ atleast_2d()

template<class E >
auto xt::atleast_2d ( E && e)
inline

Expand to at least 2D.

See also
atleast_Nd

Definition at line 697 of file xmanipulation.hpp.

◆ atleast_3d()

template<class E >
auto xt::atleast_3d ( E && e)
inline

Expand to at least 3D.

See also
atleast_Nd

Definition at line 709 of file xmanipulation.hpp.

◆ atleast_Nd()

template<std::size_t N, class E >
auto xt::atleast_Nd ( E && e)
inline

Expand dimensions of xexpression to at least N

This adds newaxis() slices to a strided_view until the dimension of the view reaches at least N. Note: dimensions are added equally at the beginning and the end. For example, a 1-D array of shape (N,) becomes a view of shape (1, N, 1).

Parameters
einput xexpression
Template Parameters
Nthe number of requested dimensions
Returns
strided_view with expanded dimensions

Definition at line 658 of file xmanipulation.hpp.

◆ expand_dims()

template<class E >
auto xt::expand_dims ( E && e,
std::size_t axis )
inline

Expand the shape of an xexpression.

Insert a new axis that will appear at the axis position in the expanded array shape. This will return a strided_view with a xt::newaxis() at the indicated axis.

Parameters
einput xexpression
axisaxis to expand
Returns
returns a strided_view with expanded dimension

Definition at line 633 of file xmanipulation.hpp.

◆ flatten()

template<layout_type L = ::xt::layout_type::row_major, class E >
auto xt::flatten ( E && e)
inline

Return a flatten view of the given expression.

No copy is made. This method is equivalent to ravel and is provided for API sameness with NumPy.

Parameters
ethe input expression
Template Parameters
Lthe layout used to read the elements of e. If no parameter is specified, XTENSOR_DEFAULT_TRAVERSAL is used.
Ethe type of the expression
See also
ravel

Definition at line 442 of file xmanipulation.hpp.

◆ flip() [1/2]

template<class E >
auto xt::flip ( E && e)
inline

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

Parameters
ethe input xexpression
Returns
returns a view with the result of the flip.

Definition at line 800 of file xmanipulation.hpp.

◆ flip() [2/2]

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

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

Parameters
ethe input xexpression
axisthe axis along which elements should be reversed
Returns
returns a view with the result of the flip

Definition at line 823 of file xmanipulation.hpp.

◆ hsplit()

template<class E >
auto xt::hsplit ( E & e,
std::size_t n )
inline

Split an xexpression into subexpressions horizontally (column-wise)

This method is equivalent to split(e, n, 1).

Parameters
einput xexpression
nnumber of elements to return

Definition at line 768 of file xmanipulation.hpp.

◆ moveaxis()

template<class E >
auto xt::moveaxis ( E && e,
std::ptrdiff_t src,
std::ptrdiff_t dest )
inline

Return a new expression with an axis move to a new position.

Parameters
eThe input expression
srcOriginal position of the axis to move
destDestination position for the original axis.

Definition at line 368 of file xmanipulation.hpp.

◆ ravel()

template<layout_type L = ::xt::layout_type::row_major, class E >
auto xt::ravel ( E && e)
inline

Return a flatten view of the given expression.

No copy is made.

Parameters
ethe input expression
Template Parameters
Lthe layout used to read the elements of e. If no parameter is specified, XTENSOR_DEFAULT_TRAVERSAL is used.
Ethe type of the expression

Definition at line 417 of file xmanipulation.hpp.

◆ repeat() [1/3]

template<class E >
auto xt::repeat ( E && e,
const std::vector< std::size_t > & repeats,
std::size_t axis )
inline

Repeat elements of an expression along a given axis.

Parameters
ethe input xexpression
repeatsThe number of repetition of each elements. The size of repeats must match the shape of the given axis.
axisthe axis along which to repeat the value
Returns
an expression which as the same shape as e, except along the given axis

Definition at line 1123 of file xmanipulation.hpp.

◆ repeat() [2/3]

template<class E >
auto xt::repeat ( E && e,
std::size_t repeats,
std::size_t axis )
inline

Repeat elements of an expression along a given axis.

Parameters
ethe input xexpression
repeatsThe number of repetition of each elements. repeats is broadcasted to fit the shape of the given axis.
axisthe axis along which to repeat the value
Returns
an expression which as the same shape as e, except along the given axis

Definition at line 1103 of file xmanipulation.hpp.

◆ repeat() [3/3]

template<class E >
auto xt::repeat ( E && e,
std::vector< std::size_t > && repeats,
std::size_t axis )
inline

Repeat elements of an expression along a given axis.

Parameters
ethe input xexpression
repeatsThe number of repetition of each elements. The size of repeats must match the shape of the given axis.
axisthe axis along which to repeat the value
Returns
an expression which as the same shape as e, except along the given axis

Definition at line 1139 of file xmanipulation.hpp.

◆ roll() [1/2]

template<class E >
auto xt::roll ( E && e,
std::ptrdiff_t shift )
inline

Roll an expression.

The expression is flatten before shifting, after which the original shape is restore. Elements that roll beyond the last position are re-introduced at the first. This function does not change the input expression.

Parameters
ethe input xexpression
shiftthe number of places by which elements are shifted
Returns
a roll of the input expression

Definition at line 952 of file xmanipulation.hpp.

◆ roll() [2/2]

template<class E >
auto xt::roll ( E && e,
std::ptrdiff_t shift,
std::ptrdiff_t axis )
inline

Roll an expression along a given axis.

Elements that roll beyond the last position are re-introduced at the first. This function does not change the input expression.

Parameters
ethe input xexpression
shiftthe number of places by which elements are shifted
axisthe axis along which elements are shifted.
Returns
a roll of the input expression

Definition at line 1049 of file xmanipulation.hpp.

◆ rot90()

template<std::ptrdiff_t N = 1, class E >
auto xt::rot90 ( E && e,
const std::array< std::ptrdiff_t, 2 > & axes )
inline

Rotate an array by 90 degrees in the plane specified by axes.

Rotation direction is from the first towards the second axis.

Parameters
ethe input xexpression
axesthe array is rotated in the plane defined by the axes. Axes must be different.
Template Parameters
Nnumber of times the array is rotated by 90 degrees. Default is 1.
Returns
returns a view with the result of the rotation

Definition at line 919 of file xmanipulation.hpp.

◆ split()

template<class E >
auto xt::split ( E & e,
std::size_t n,
std::size_t axis )
inline

Split xexpression along axis into subexpressions.

This splits an xexpression along the axis in n equal parts and returns a vector of strided_view. Calling split with axis > dimension of e or a n that does not result in an equal division of the xexpression will throw a runtime_error.

Parameters
einput xexpression
nnumber of elements to return
axisaxis along which to split the expression

Definition at line 732 of file xmanipulation.hpp.

◆ squeeze() [1/2]

template<class E >
auto xt::squeeze ( E && e)
inline

Returns a squeeze view of the given expression.

No copy is made. Squeezing an expression removes dimensions of extent 1.

Parameters
ethe input expression
Template Parameters
Ethe type of the expression

Definition at line 513 of file xmanipulation.hpp.

◆ squeeze() [2/2]

template<class E , class S , class Tag = check_policy::none, std::enable_if_t<!xtl::is_integral< S >::value, int > = 0>
auto xt::squeeze ( E && e,
S && axis,
Tag check_policy )
inline

Remove single-dimensional entries from the shape of an xexpression.

Parameters
einput xexpression
axisinteger or container of integers, select a subset of single-dimensional entries of the shape.
check_policyselect check_policy. With check_policy::full(), selecting an axis which is greater than one will throw a runtime_error.

Definition at line 592 of file xmanipulation.hpp.

◆ swapaxes()

template<class E >
auto xt::swapaxes ( E && e,
std::ptrdiff_t axis1,
std::ptrdiff_t axis2 )
inline

Return a new expression with two axes interchanged.

The two axis parameter axis and axis2 are interchangable.

Parameters
eThe input expression
axis1First axis to swap
axis2Second axis to swap

Definition at line 314 of file xmanipulation.hpp.

◆ transpose() [1/2]

template<class E >
auto xt::transpose ( E && e)
inlinenoexcept

Returns a transpose view by reversing the dimensions of xexpression e.

Parameters
ethe input expression

Definition at line 237 of file xmanipulation.hpp.

◆ transpose() [2/2]

template<class E , class S , class Tag = check_policy::none>
auto xt::transpose ( E && e,
S && permutation,
Tag check_policy )
inline

Returns a transpose view by permuting the xexpression e with permutation.

Parameters
ethe input expression
permutationthe sequence containing permutation
check_policythe check level (check_policy::full() or check_policy::none())
Template Parameters
Tagselects the level of error checking on permutation vector defaults to check_policy::none.

Definition at line 269 of file xmanipulation.hpp.

◆ trim_zeros()

template<class E >
auto xt::trim_zeros ( E && e,
const std::string & direction )
inline

Trim zeros at beginning, end or both of 1D sequence.

Parameters
einput xexpression
directionstring of either 'f' for trim from beginning, 'b' for trim from end or 'fb' (default) for both.
Returns
returns a view without zeros at the beginning and end

Definition at line 475 of file xmanipulation.hpp.

◆ vsplit()

template<class E >
auto xt::vsplit ( E & e,
std::size_t n )
inline

Split an xexpression into subexpressions vertically (row-wise)

This method is equivalent to split(e, n, 0).

Parameters
einput xexpression
nnumber of elements to return

Definition at line 783 of file xmanipulation.hpp.