NaN functions¶
xtensor provides the following functions that deal with NaNs in xexpressions:
Defined in xtensor/xmath.hpp
-
template<class
E>
autoxt::nan_to_num(E &&e)¶ Convert nan or +/- inf to numbers.
This functions converts nan to 0, and +inf to the highest, -inf to the lowest floating point value of the same type.
- Return
an xexpression
- Parameters
e: input xexpression
-
template<class
T= void, classE, classX, classEVS= std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<xtl::negation<is_reducer_options<X>>, xtl::negation<xtl::is_integral<X>>> = 0>
autoxt::nanmin(E &&e, X &&axes, EVS es = EVS()) Minimum element over given axes, excluding nans.
Returns an xreducer for the minimum of elements over given axes, ignoring nans.
- Warning
Casting the result to an integer type can cause undefined behavior.
- Return
an xreducer
- Parameters
e: an xexpressionaxes: the axes along which the minimum is found (optional)es: evaluation strategy of the reducer (optional)
- Template Parameters
T: the result type. The default isE::value_type.
-
template<class
T= void, classE, classX, classEVS= std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<xtl::negation<is_reducer_options<X>>, xtl::negation<xtl::is_integral<X>>> = 0>
autoxt::nanmax(E &&e, X &&axes, EVS es = EVS()) Maximum element along given axes, excluding nans.
Returns an xreducer for the sum of elements over given axes, replacing nan with 0.
- Warning
Casting the result to an integer type can cause undefined behavior.
- Return
an xreducer
- Parameters
e: an xexpressionaxes: the axes along which the sum is performed (optional)es: evaluation strategy of the reducer (optional)
- Template Parameters
T: the result type. The default isE::value_type.
-
template<class
T= void, classE, classX, classEVS= std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<xtl::negation<is_reducer_options<X>>, xtl::negation<xtl::is_integral<X>>> = 0>
autoxt::nansum(E &&e, X &&axes, EVS es = EVS()) Sum of elements over given axes, replacing nan with 0.
Returns an xreducer for the sum of elements over given axes, replacing nan with 0.
- Return
an xreducer
- Parameters
e: an xexpressionaxes: the axes along which the sum is performed (optional)es: evaluation strategy of the reducer (optional)
- Template Parameters
T: the value type used for internal computation. The default isE::value_type.Tis also used for determining the value type of the result, which is the type ofT() + E::value_type(). You can passbig_promote_value_type_t<E>to avoid overflow in computation.
-
template<class
T= void, classE, classX, classEVS= std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<xtl::negation<is_reducer_options<X>>> = 0>
autoxt::nanmean(E &&e, X &&axes, EVS es = EVS()) Mean of elements over given axes, excluding nans.
Returns an xreducer for the mean of elements over given axes, excluding nans.
- Return
an xexpression
- Parameters
e: an xexpressionaxes: the axes along which the mean is computed (optional)es: the evaluation strategy (optional)
- Template Parameters
T: the result type. The default isE::value_type. You can passbig_promote_value_type_t<E>to avoid overflow in computation.
-
template<class
T= void, classE, classX, classEVS= std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<xtl::negation<is_reducer_options<X>>> = 0>
autoxt::nanvar(E &&e, X &&axes, EVS es = EVS()) Compute the variance along the specified axes, excluding nans.
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.
- Return
an xexpression
- See
nanstd, nanmean
- Parameters
e: an xexpressionaxes: the axes along which the variance is computed (optional)es: evaluation strategy to use (lazy (default), or immediate)
- Template Parameters
T: the result type. The default isE::value_type. You can passbig_promote_value_type_t<E>to avoid overflow in computation.
-
template<class
T= void, classE, classX, classEVS= std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<xtl::negation<is_reducer_options<X>>> = 0>
autoxt::nanstd(E &&e, X &&axes, EVS es = EVS()) Compute the standard deviation along the specified axis, excluding nans.
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.
- Return
an xexpression
- See
nanvar, nanmean
- Parameters
e: an xexpressionaxes: the axes along which the standard deviation is computed (optional)es: evaluation strategy to use (lazy (default), or immediate)
- Template Parameters
T: the result type. The default isE::value_type. You can passbig_promote_value_type_t<E>to avoid overflow in computation.
-
template<class
T= void, classE, classX, classEVS= std::tuple<evaluation_strategy::lazy_type>, xtl::check_concept<xtl::negation<is_reducer_options<X>>, xtl::negation<xtl::is_integral<X>>> = 0>
autoxt::nanprod(E &&e, X &&axes, EVS es = EVS()) Product of elements over given axes, replacing nan with 1.
Returns an xreducer for the sum of elements over given axes, replacing nan with 1.
- Return
an xreducer
- Parameters
e: an xexpressionaxes: the axes along which the sum is performed (optional)es: evaluation strategy of the reducer (optional)
- Template Parameters
T: the value type used for internal computation. The default isE::value_type.Tis also used for determining the value type of the result, which is the type ofT() * E::value_type(). You can passbig_promote_value_type_t<E>to avoid overflow in computation.
-
template<class
T= void, classE>
autoxt::nancumsum(E &&e)
-
template<class
T= void, classE>
autoxt::nancumsum(E &&e, std::ptrdiff_t axis) Cumulative sum, replacing nan with 0.
Returns an xaccumulator for the sum of elements over given axis, replacing nan with 0.
- Return
an xaccumulator
- Parameters
e: an xexpressionaxis: the axis along which the elements are accumulated (optional)
- Template Parameters
T: the value type used for internal computation. The default isE::value_type.Tis also used for determining the value type of the result, which is the type ofT() + E::value_type(). You can passbig_promote_value_type_t<E>to avoid overflow in computation.
-
template<class
T= void, classE>
autoxt::nancumprod(E &&e)
-
template<class
T= void, classE>
autoxt::nancumprod(E &&e, std::ptrdiff_t axis) Cumulative product, replacing nan with 1.
Returns an xaccumulator for the product of elements over given axis, replacing nan with 1.
- Return
an xaccumulator
- Parameters
e: an xexpressionaxis: the axis along which the elements are accumulated (optional)
- Template Parameters
T: the value type used for internal computation. The default isE::value_type.Tis also used for determining the value type of the result, which is the type ofT() * E::value_type(). You can passbig_promote_value_type_t<E>to avoid overflow in computation.