xtensor
Loading...
Searching...
No Matches
reducing functions

Functions

template<class T = void, class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > >, xtl::negation< xtl::is_integral< std::decay_t< X > > > > = 0>
auto xt::sum (E &&e, X &&axes, EVS es=EVS())
 Sum of elements over given axes.
 
template<class T = void, class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > >, xtl::negation< xtl::is_integral< std::decay_t< X > > > > = 0>
auto xt::prod (E &&e, X &&axes, EVS es=EVS())
 Product of elements over given axes.
 
template<class T = void, class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > > > = 0>
auto xt::mean (E &&e, X &&axes, EVS es=EVS())
 Mean of elements over given axes.
 
template<class T = void, class E , class W , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_reducer_options< EVS >, xtl::negation< xtl::is_integral< X > > > = 0>
auto xt::average (E &&e, W &&weights, X &&axes, EVS ev=EVS())
 Average of elements over given axes using weights.
 
template<class T = void, class E , class X , class D , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > >, xtl::is_integral< D > > = 0>
auto xt::variance (E &&e, X &&axes, const D &ddof, EVS es=EVS())
 Compute the variance along the specified axes.
 
template<class T = void, class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > > > = 0>
auto xt::stddev (E &&e, X &&axes, EVS es=EVS())
 Compute the standard deviation along the specified axis.
 
template<class E , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_reducer_options< EVS > > = 0>
auto xt::minmax (E &&e, EVS es=EVS())
 Minimum and maximum among the elements of an array or expression.
 
template<class T >
auto xt::diff (const xexpression< T > &a, std::size_t n=1, std::ptrdiff_t axis=-1)
 Calculate the n-th discrete difference along the given axis.
 
template<class T >
auto xt::trapz (const xexpression< T > &y, double dx=1.0, std::ptrdiff_t axis=-1)
 Integrate along the given axis using the composite trapezoidal rule.
 
template<class T , class E >
auto xt::trapz (const xexpression< T > &y, const xexpression< E > &x, std::ptrdiff_t axis=-1)
 Integrate along the given axis using the composite trapezoidal rule.
 
template<class E , class X , class EVS , class >
auto xt::norm_l0 (E &&e, X &&axes, EVS es) noexcept
 L0 (count) pseudo-norm of an array-like argument over given axes.
 
template<class E , class X , class EVS , class >
auto xt::norm_l1 (E &&e, X &&axes, EVS es) noexcept
 L1 norm of an array-like argument over given axes.
 
template<class E , class X , class EVS , class >
auto xt::norm_sq (E &&e, X &&axes, EVS es) noexcept
 Squared L2 norm of an array-like argument over given axes.
 
template<class E , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_xexpression< E > > = 0>
auto xt::norm_l2 (E &&e, EVS es=EVS()) noexcept
 L2 norm of a scalar or array-like argument.
 
template<class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_xexpression< E >, xtl::negation< is_reducer_options< X > > > = 0>
auto xt::norm_l2 (E &&e, X &&axes, EVS es=EVS()) noexcept
 L2 norm of an array-like argument over given axes.
 
template<class E , class X , class EVS , class >
auto xt::norm_linf (E &&e, X &&axes, EVS es) noexcept
 Infinity (maximum) norm of an array-like argument over given axes.
 
template<class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > > > = 0>
auto xt::norm_lp_to_p (E &&e, double p, X &&axes, EVS es=EVS()) noexcept
 p-th power of the Lp norm of an array-like argument over given axes.
 
template<class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > > > = 0>
auto xt::norm_lp (E &&e, double p, X &&axes, EVS es=EVS())
 Lp norm of an array-like argument over given axes.
 
template<class E , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_xexpression< E > > = 0>
auto xt::norm_induced_l1 (E &&e, EVS es=EVS())
 Induced L1 norm of a matrix.
 
template<class E , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_xexpression< E > > = 0>
auto xt::norm_induced_linf (E &&e, EVS es=EVS())
 Induced L-infinity norm of a matrix.
 

Detailed Description

Function Documentation

◆ average()

template<class T = void, class E , class W , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_reducer_options< EVS >, xtl::negation< xtl::is_integral< X > > > = 0>
auto xt::average ( E && e,
W && weights,
X && axes,
EVS ev = EVS() )
inline

Average of elements over given axes using weights.

Returns an xreducer for the mean of elements over given axes.

Parameters
ean xexpression
weightsxexpression containing weights associated with the values in e
axesthe axes along which the mean is computed (optional)
Template Parameters
Tthe value type used for internal computation. The default is E::value_type. Tis also used for determining the value type of the result, which is the type of T() + E::value_type(). You can passbig_promote_value_type_t<E>` to avoid overflow in computation.
Returns
an xexpression
See also
mean

Definition at line 1976 of file xmath.hpp.

◆ diff()

template<class T >
auto xt::diff ( const xexpression< T > & a,
std::size_t n = 1,
std::ptrdiff_t axis = -1 )

Calculate the n-th discrete difference along the given axis.

Calculate the n-th discrete difference along the given axis. This function is not lazy (might change in the future).

Parameters
aan xexpression
nThe number of times values are differenced. If zero, the input is returned as-is. (optional)
axisThe axis along which the difference is taken, default is the last axis.
Returns
an xarray

Definition at line 2911 of file xmath.hpp.

◆ mean()

template<class T = void, class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > > > = 0>
auto xt::mean ( E && e,
X && axes,
EVS es = EVS() )
inline

Mean of elements over given axes.

Returns an xreducer for the mean of elements over given axes.

Parameters
ean xexpression
axesthe axes along which the mean is computed (optional)
esthe evaluation strategy (optional)
Template Parameters
Tthe value type used for internal computation. The default is E::value_type. T is also used for determining the value type of the result, which is the type of T() + E::value_type(). You can pass big_promote_value_type_t<E> to avoid overflow in computation.
Returns
an xexpression

Definition at line 1935 of file xmath.hpp.

◆ minmax()

template<class E , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_reducer_options< EVS > > = 0>
auto xt::minmax ( E && e,
EVS es = EVS() )
inline

Minimum and maximum among the elements of an array or expression.

Returns an xreducer for the minimum and maximum of an expression's elements.

Parameters
ean xexpression
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xexpression of type std::array<value_type, 2>, whose first and second element represent the minimum and maximum respectively

Definition at line 2234 of file xmath.hpp.

◆ norm_induced_l1()

template<class E , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_xexpression< E > > = 0>
auto xt::norm_induced_l1 ( E && e,
EVS es = EVS() )
inline

Induced L1 norm of a matrix.

Returns an xreducer for the induced L1 norm (i.e. the maximum of the L1 norms of e's columns).

Parameters
ea 2D xexpression
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xreducer (or xcontainer, depending on evaluation strategy)

Definition at line 630 of file xnorm.hpp.

◆ norm_induced_linf()

template<class E , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_xexpression< E > > = 0>
auto xt::norm_induced_linf ( E && e,
EVS es = EVS() )
inline

Induced L-infinity norm of a matrix.

Returns an xreducer for the induced L-infinity norm (i.e. the maximum of the L1 norms of e's rows).

Parameters
ea 2D xexpression
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xreducer (or xcontainer, depending on evaluation strategy)

Definition at line 650 of file xnorm.hpp.

◆ norm_l0()

template<class E , class X , class EVS , class >
auto xt::norm_l0 ( E && e,
X && axes,
EVS es )
noexcept

L0 (count) pseudo-norm of an array-like argument over given axes.

Returns an xreducer for the L0 pseudo-norm of the elements across given axes.

Parameters
ean xexpression
axesthe axes along which the norm is computed (optional)
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xreducer (or xcontainer, depending on evaluation strategy) When no axes are provided, the norm is calculated over the entire array. In this case, the reducer represents a scalar result, otherwise an array of appropriate dimension.

◆ norm_l1()

template<class E , class X , class EVS , class >
auto xt::norm_l1 ( E && e,
X && axes,
EVS es )
noexcept

L1 norm of an array-like argument over given axes.

Returns an xreducer for the L1 norm of the elements across given axes.

Parameters
ean xexpression
axesthe axes along which the norm is computed (optional)
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xreducer (or xcontainer, depending on evaluation strategy) When no axes are provided, the norm is calculated over the entire array. In this case, the reducer represents a scalar result, otherwise an array of appropriate dimension.

◆ norm_l2() [1/2]

template<class E , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_xexpression< E > > = 0>
auto xt::norm_l2 ( E && e,
EVS es = EVS() )
inlinenoexcept

L2 norm of a scalar or array-like argument.

Parameters
ean xexpression
esevaluation strategy to use (lazy (default), or immediate) For scalar types: implemented as abs(t)
otherwise: implemented as sqrt(norm_sq(t)).

Definition at line 494 of file xnorm.hpp.

◆ norm_l2() [2/2]

template<class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< is_xexpression< E >, xtl::negation< is_reducer_options< X > > > = 0>
auto xt::norm_l2 ( E && e,
X && axes,
EVS es = EVS() )
inlinenoexcept

L2 norm of an array-like argument over given axes.

Returns an xreducer for the L2 norm of the elements across given axes.

Parameters
ean xexpression
esevaluation strategy to use (lazy (default), or immediate)
axesthe axes along which the norm is computed
Returns
an xreducer (specifically: sqrt(norm_sq(e, axes))) (or xcontainer, depending on evaluation strategy)

Definition at line 516 of file xnorm.hpp.

◆ norm_linf()

template<class E , class X , class EVS , class >
auto xt::norm_linf ( E && e,
X && axes,
EVS es )
noexcept

Infinity (maximum) norm of an array-like argument over given axes.

Returns an xreducer for the infinity norm of the elements across given axes.

Parameters
ean xexpression
axesthe axes along which the norm is computed (optional)
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xreducer (or xcontainer, depending on evaluation strategy) When no axes are provided, the norm is calculated over the entire array. In this case, the reducer represents a scalar result, otherwise an array of appropriate dimension.

◆ norm_lp()

template<class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > > > = 0>
auto xt::norm_lp ( E && e,
double p,
X && axes,
EVS es = EVS() )
inline

Lp norm of an array-like argument over given axes.

Returns an xreducer for the Lp norm (p != 0) of the elements across given axes.

Parameters
ean xexpression
p
axesthe axes along which the norm is computed (optional)
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xreducer (or xcontainer, depending on evaluation strategy) When no axes are provided, the norm is calculated over the entire array. In this case, the reducer represents a scalar result, otherwise an array of appropriate dimension.

Definition at line 601 of file xnorm.hpp.

◆ norm_lp_to_p()

template<class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > > > = 0>
auto xt::norm_lp_to_p ( E && e,
double p,
X && axes,
EVS es = EVS() )
inlinenoexcept

p-th power of the Lp norm of an array-like argument over given axes.

Returns an xreducer for the p-th power of the Lp norm of the elements across given axes.

Parameters
ean xexpression
p
axesthe axes along which the norm is computed (optional)
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xreducer (or xcontainer, depending on evaluation strategy) When no axes are provided, the norm is calculated over the entire array. In this case, the reducer represents a scalar result, otherwise an array of appropriate dimension.

Definition at line 557 of file xnorm.hpp.

◆ norm_sq()

template<class E , class X , class EVS , class >
auto xt::norm_sq ( E && e,
X && axes,
EVS es )
noexcept

Squared L2 norm of an array-like argument over given axes.

Returns an xreducer for the squared L2 norm of the elements across given axes.

Parameters
ean xexpression
axesthe axes along which the norm is computed (optional)
esevaluation strategy to use (lazy (default), or immediate)
Returns
an xreducer (or xcontainer, depending on evaluation strategy) When no axes are provided, the norm is calculated over the entire array. In this case, the reducer represents a scalar result, otherwise an array of appropriate dimension.

◆ prod()

template<class T = void, class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > >, xtl::negation< xtl::is_integral< std::decay_t< X > > > > = 0>
auto xt::prod ( E && e,
X && axes,
EVS es = EVS() )
inline

Product of elements over given axes.

Returns an xreducer for the product of elements over given axes.

Parameters
ean xexpression
axesthe axes along which the product is computed (optional)
ddofdelta degrees of freedom (optional). The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.
esevaluation strategy of the reducer
Template Parameters
Tthe value type used for internal computation. The default is E::value_type. T is also used for determining the value type of the result, which is the type of T() * E::value_type(). You can pass big_promote_value_type_t<E> to avoid overflow in computation.
Returns
an xreducer

Definition at line 1861 of file xmath.hpp.

◆ stddev()

template<class T = void, class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > > > = 0>
auto xt::stddev ( E && e,
X && axes,
EVS es = EVS() )
inline

Compute the standard deviation along the specified axis.

Returns the standard deviation, a measure of the spread of a distribution, of the array elements. The standard deviation is computed for the flattened array by default, otherwise over the specified axis.

Note: this function is not yet specialized for complex numbers.

Parameters
ean xexpression
axesthe axes along which the standard deviation is computed (optional)
esevaluation strategy to use (lazy (default), or immediate)
Template Parameters
Tthe value type used for internal computation. The default is E::value_type. Tis also used for determining the value type of the result, which is the type of T() + E::value_type(). You can pass big_promote_value_type_t<E> to avoid overflow in computation.
Returns
an xexpression
See also
variance, mean

Definition at line 2181 of file xmath.hpp.

◆ sum()

template<class T = void, class E , class X , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > >, xtl::negation< xtl::is_integral< std::decay_t< X > > > > = 0>
auto xt::sum ( E && e,
X && axes,
EVS es = EVS() )
inline

Sum of elements over given axes.

Returns an xreducer for the sum of elements over given axes.

Parameters
ean xexpression
axesthe axes along which the sum is performed (optional)
esevaluation strategy of the reducer
Template Parameters
Tthe value type used for internal computation. The default is E::value_type. T is also used for determining the value type of the result, which is the type of T() + E::value_type(). You can pass big_promote_value_type_t<E> to avoid overflow in computation.
Returns
an xreducer

Definition at line 1841 of file xmath.hpp.

◆ trapz() [1/2]

template<class T , class E >
auto xt::trapz ( const xexpression< T > & y,
const xexpression< E > & x,
std::ptrdiff_t axis = -1 )

Integrate along the given axis using the composite trapezoidal rule.

Returns definite integral as approximated by trapezoidal rule. This function is not lazy (might change in the future).

Parameters
yan xexpression
xan xexpression representing the sample points corresponding to the y values.
axisthe axis along which to integrate.
Returns
an xarray

Definition at line 2975 of file xmath.hpp.

◆ trapz() [2/2]

template<class T >
auto xt::trapz ( const xexpression< T > & y,
double dx = 1.0,
std::ptrdiff_t axis = -1 )

Integrate along the given axis using the composite trapezoidal rule.

Returns definite integral as approximated by trapezoidal rule. This function is not lazy (might change in the future).

Parameters
yan xexpression
dxthe spacing between sample points (optional)
axisthe axis along which to integrate.
Returns
an xarray

Definition at line 2948 of file xmath.hpp.

◆ variance()

template<class T = void, class E , class X , class D , class EVS = std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept< xtl::negation< is_reducer_options< X > >, xtl::is_integral< D > > = 0>
auto xt::variance ( E && e,
X && axes,
const D & ddof,
EVS es = EVS() )
inline

Compute the variance along the specified axes.

Returns the variance of the array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axes.

Note: this function is not yet specialized for complex numbers.

Parameters
ean xexpression
axesthe axes along which the variance is computed (optional)
ddofdelta degrees of freedom (optional). The divisor used in calculations is N - ddof, where N represents the number of elements. By default ddof is zero.
esevaluation strategy to use (lazy (default), or immediate)
Template Parameters
Tthe value type used for internal computation. The default is E::value_type. Tis also used for determining the value type of the result, which is the type of T() + E::value_type(). You can pass big_promote_value_type_t<E> to avoid overflow in computation.
Returns
an xexpression
See also
stddev, mean

Definition at line 2120 of file xmath.hpp.