xmanipulation¶
Defined in xtensor/xmanipulation.hpp
-
template<std::size_t
N
, classE
>
autoxt
::
atleast_Nd
(E &&e)¶ Expand dimensions of xexpression to at least
N
This adds
newaxis()
slices to astrided_view
until the dimension of the view reaches at leastN
. 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).- Return
strided_view
with expanded dimensions- Parameters
e
: input xexpression
- Template Parameters
N
: the number of requested dimensions
-
template<class
E
>
autoxt
::
expand_dims
(E &&e, std::size_t axis)¶ 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 axt::newaxis()
at the indicated axis.- Return
returns a
strided_view
with expanded dimension- Parameters
e
: input xexpressionaxis
: axis to expand
-
template<layout_type
L
= xt::layout_type::row_major, classE
>
autoxt
::
flatten
(E &&e)¶ Returns 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.
- See
- Parameters
e
: the input expression
- Template Parameters
L
: the layout used to read the elements of e. If no parameter is specified, XTENSOR_DEFAULT_TRAVERSAL is used.E
: the type of the expression
-
template<layout_type
L
, classT
>
autoxt
::
flatnonzero
(const T &arr)¶ return indices that are non-zero in the flattened version of arr, equivalent to nonzero(ravel<layout_type>(arr))[0];
- Return
indices that are non-zero in the flattened version of arr
- Parameters
arr
: input array
-
template<class
E
>
autoxt
::
flip
(E &&e, 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 toxt::flip(arr, 0)
,fliplr(arr)
toxt::flip(arr, 1)
.- Return
returns a view with the result of the flip
- Parameters
e
: the input xexpressionaxis
: the axis along which elements should be reversed
-
template<layout_type
L
= xt::layout_type::row_major, classE
>
autoxt
::
ravel
(E &&e)¶ Returns a flatten view of the given expression.
No copy is made.
- Parameters
e
: the input expression
- Template Parameters
L
: the layout used to read the elements of e. If no parameter is specified, XTENSOR_DEFAULT_TRAVERSAL is used.E
: the type of the expression
-
template<class
E
>
autoxt
::
repeat
(E &&e, std::size_t repeats, std::size_t axis) Repeats elements of an expression along a given axis.
- Return
an expression which as the same shape as e, except along the given axis
- Parameters
e
: the input xexpressionrepeats
: The number of repetition of each elements. repeats is broadcasted to fit the shape of the given axis.axis
: the axis along which to repeat the value
-
template<class
E
>
autoxt
::
repeat
(E &&e, const std::vector<std::size_t> &repeats, std::size_t axis) Repeats elements of an expression along a given axis.
- Return
an expression which as the same shape as e, except along the given axis
- Parameters
e
: the input xexpressionrepeats
: The number of repetition of each elements. The size of repeats must match the shape of the given axis.axis
: the axis along which to repeat the value
-
template<class
E
>
autoxt
::
repeat
(E &&e, std::vector<std::size_t> &&repeats, std::size_t axis) Repeats elements of an expression along a given axis.
- Return
an expression which as the same shape as e, except along the given axis
- Parameters
e
: the input xexpressionrepeats
: The number of repetition of each elements. The size of repeats must match the shape of the given axis.axis
: the axis along which to repeat the value
-
template<class
E
>
autoxt
::
roll
(E &&e, std::ptrdiff_t shift) 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.
- Return
a roll of the input expression
- Parameters
e
: the input xexpressionshift
: the number of places by which elements are shifted
-
template<class
E
>
autoxt
::
roll
(E &&e, std::ptrdiff_t shift, std::ptrdiff_t axis) 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.
- Return
a roll of the input expression
- Parameters
e
: the input xexpressionshift
: the number of places by which elements are shiftedaxis
: the axis along which elements are shifted.
-
template<std::ptrdiff_t
N
= 1, classE
>
autoxt
::
rot90
(E &&e, const std::array<std::ptrdiff_t, 2> &axes = {0, 1})¶ Rotate an array by 90 degrees in the plane specified by axes.
Rotation direction is from the first towards the second axis.
- Return
returns a view with the result of the rotation
- Parameters
e
: the input xexpressionaxes
: the array is rotated in the plane defined by the axes. Axes must be different.
- Template Parameters
N
: number of times the array is rotated by 90 degrees. Default is 1.
-
template<class
E
>
autoxt
::
split
(E &e, std::size_t n, std::size_t axis = 0)¶ Split xexpression along axis into subexpressions.
This splits an xexpression along the axis in
n
equal parts and returns a vector ofstrided_view
. Calling split with axis > dimension of e or an
that does not result in an equal division of the xexpression will throw a runtime_error.- Parameters
e
: input xexpressionn
: number of elements to returnaxis
: axis along which to split the expression
-
template<class
E
>
autoxt
::
hsplit
(E &e, std::size_t n)¶ Split an xexpression into subexpressions horizontally (column-wise)
This method is equivalent to
split(e, n, 1)
.- Parameters
e
: input xexpressionn
: number of elements to return
-
template<class
E
>
autoxt
::
vsplit
(E &e, std::size_t n)¶ Split an xexpression into subexpressions vertically (row-wise)
This method is equivalent to
split(e, n, 0)
.- Parameters
e
: input xexpressionn
: number of elements to return
-
template<class
E
>
autoxt
::
squeeze
(E &&e) Returns a squeeze view of the given expression.
No copy is made. Squeezing an expression removes dimensions of extent 1.
- Parameters
e
: the input expression
- Template Parameters
E
: the type of the expression
-
template<class
E
, classS
, classTag
= check_policy::none, std::enable_if_t<!xtl::is_integral<S>::value, int> = 0>
autoxt
::
squeeze
(E &&e, S &&axis, Tag check_policy = Tag()) Remove single-dimensional entries from the shape of an xexpression.
- Parameters
e
: input xexpressionaxis
: integer or container of integers, select a subset of single-dimensional entries of the shape.check_policy
: select check_policy. With check_policy::full(), selecting an axis which is greater than one will throw a runtime_error.
-
template<class
E
>
autoxt
::
transpose
(E &&e) Returns a transpose view by reversing the dimensions of xexpression e.
- Parameters
e
: the input expression
-
template<class
E
, classS
, classTag
= check_policy::none>
autoxt
::
transpose
(E &&e, S &&permutation, Tag check_policy = Tag()) Returns a transpose view by permuting the xexpression e with
permutation
.- Parameters
e
: the input expressionpermutation
: the sequence containing permutationcheck_policy
: the check level (check_policy::full() or check_policy::none())
- Template Parameters
Tag
: selects the level of error checking on permutation vector defaults to check_policy::none.
-
template<class
E
>
autoxt
::
trim_zeros
(E &&e, const std::string &direction = "fb")¶ Trim zeros at beginning, end or both of 1D sequence.
- Return
returns a view without zeros at the beginning and end
- Parameters
e
: input xexpressiondirection
: string of either ‘f’ for trim from beginning, ‘b’ for trim from end or ‘fb’ (default) for both.