xtensor Logo

INSTALLATION

  • Installation
  • Changelog

USAGE

  • Getting started
  • Expressions and lazy evaluation
  • Arrays and tensors
  • Scalars and 0-D expressions
  • Adapting 1-D containers
  • Operators and functions
  • Views
  • Indices
  • Expression builders
  • Missing values
  • Histogram
  • Random
  • Tensor Rank
  • File input and output
  • Build and configuration
  • Common pitfalls

QUICK REFERENCE

  • Basics
  • Builders
  • Operators
  • Mathematical functions
  • Reductions
  • Views
  • Iterators
  • Manipulation
  • Chunked arrays

API REFERENCE

  • Expressions and semantic
  • Containers and views
  • Iterators
  • Functions and generators
  • IO Operations
  • Mathematical functions
    • Operators and related functions
      • operator+()
      • operator-()
      • operator+()
      • operator-()
      • operator*()
      • operator/()
      • operator%()
      • operator||()
      • operator&&()
      • operator!()
      • where()
      • nonzero()
      • where()
      • argwhere()
      • any()
      • all()
      • isin()
      • isin()
      • isin()
      • in1d()
      • in1d()
      • in1d()
      • operator<()
      • operator<=()
      • operator>()
      • operator>=()
      • operator==()
      • operator!=()
      • equal()
      • not_equal()
      • less()
      • less_equal()
      • greater()
      • greater_equal()
      • operator&()
      • operator|()
      • operator^()
      • operator~()
      • left_shift()
      • right_shift()
      • operator<<()
      • operator>>()
      • cast()
    • Index related functions
    • Basic functions
    • Exponential functions
    • Power functions
    • Trigonometric functions
    • Hyperbolic functions
    • Error and gamma functions
    • Nearest integer floating point operations
    • Classification functions
    • Reducing functions
    • Accumulating functions
    • NaN functions
  • Shape/index manipulation

DEVELOPER ZONE

  • Compiler workarounds
  • Build and configuration
  • Internals of xtensor
  • Extending xtensor
  • Releasing xtensor

MISCELLANEOUS

  • From NumPy to xtensor
  • Notable differences with numpy
  • Closure semantics
  • Related projects
  • Designing language bindings with xtensor
xtensor
  • Mathematical functions
  • Operators and related functions
  • View page source

Operators and related functions

Defined in xtensor/core/xmath.hpp and xtensor/core/xoperation.hpp

group Arithmetic operators

Functions

template<class E>
inline auto operator+(E &&e) noexcept -> detail::xfunction_type_t<detail::identity, E>

Identity.

Returns an xfunction for the element-wise identity of e.

Parameters:

e – an xexpression

Returns:

an xfunction

template<class E>
inline auto operator-(E &&e) noexcept -> detail::xfunction_type_t<detail::negate, E>

Opposite.

Returns an xfunction for the element-wise opposite of e.

Parameters:

e – an xexpression

Returns:

an xfunction

template<class E1, class E2>
inline auto operator+(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::plus, E1, E2>

Addition.

Returns an xfunction for the element-wise addition of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator-(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::minus, E1, E2>

Substraction.

Returns an xfunction for the element-wise substraction of e2 to e1.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator*(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::multiplies, E1, E2>

Multiplication.

Returns an xfunction for the element-wise multiplication of e1 by e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator/(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::divides, E1, E2>

Division.

Returns an xfunction for the element-wise division of e1 by e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator%(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::modulus, E1, E2>

Modulus.

Returns an xfunction for the element-wise modulus of e1 by e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

group Logical operators

Functions

template<class E1, class E2>
inline auto operator||(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::logical_or, E1, E2>

Or.

Returns an xfunction for the element-wise or of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator&&(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::logical_and, E1, E2>

And.

Returns an xfunction for the element-wise and of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E>
inline auto operator!(E &&e) noexcept -> detail::xfunction_type_t<detail::logical_not, E>

Not.

Returns an xfunction for the element-wise not of e.

Parameters:

e – an xexpression

Returns:

an xfunction

template<class E1, class E2, class E3>
inline auto where(E1 &&e1, E2 &&e2, E3 &&e3) noexcept -> detail::xfunction_type_t<detail::conditional_ternary, E1, E2, E3>

Ternary selection.

Returns an xfunction for the element-wise ternary selection (i.e. operator ? :) of e1, e2 and e3.

Parameters:
  • e1 – a boolean xexpression

  • e2 – an xexpression or a scalar

  • e3 – an xexpression or a scalar

Returns:

an xfunction

template<class T>
inline auto nonzero(const T &arr)

return vector of indices where T is not zero

Parameters:

arr – input array

Returns:

vector of vectors, one for each dimension of arr, containing the indices of the non-zero elements in that dimension

template<class T>
inline auto where(const T &condition)

return vector of indices where condition is true (equivalent to nonzero(condition))

Parameters:

condition – input array

Returns:

vector of index_types where condition is not equal to zero

template<layout_type L = ::xt::layout_type::row_major, class T>
inline auto argwhere(const T &arr)

return vector of indices where arr is not zero

See also

xt::from_indices

Template Parameters:

L – the traversal order

Parameters:

arr – input array

Returns:

vector of index_types where arr is not equal to zero (use xt::from_indices to convert)

template<class E>
inline bool any(E &&e)

Any.

Returns true if any of the values of e is truthy, false otherwise.

Parameters:

e – an xexpression

Returns:

a boolean

template<class E>
inline bool all(E &&e)

Any.

Returns true if all of the values of e are truthy, false otherwise.

Parameters:

e – an xexpression

Returns:

a boolean

template<class E, class T>
inline auto isin(E &&element, std::initializer_list<T> test_elements) noexcept

isin

Returns a boolean array of the same shape as element that is true where an element of element is in test_elements and False otherwise.

Parameters:
  • element – an xexpression

  • test_elements – an array

Returns:

a boolean array

template<class E, class F>
inline auto isin(E &&element, F &&test_elements) noexcept
requires (iterable_expression<F>)

isin

Returns a boolean array of the same shape as element that is true where an element of element is in test_elements and False otherwise.

Parameters:
  • element – an xexpression

  • test_elements – an array

Returns:

a boolean array

template<class E, std::forward_iterator I>
inline auto isin(E &&element, I &&test_elements_begin, I &&test_elements_end) noexcept

isin

Returns a boolean array of the same shape as element that is true where an element of element is in test_elements and False otherwise.

Parameters:
  • element – an xexpression

  • test_elements_begin – iterator to the beginning of an array

  • test_elements_end – iterator to the end of an array

Returns:

a boolean array

template<class E, class T>
inline auto in1d(E &&element, std::initializer_list<T> test_elements) noexcept

in1d

Returns a boolean array of the same shape as element that is true where an element of element is in test_elements and False otherwise.

Parameters:
  • element – an xexpression

  • test_elements – an array

Returns:

a boolean array

template<class E, class F>
inline auto in1d(E &&element, F &&test_elements) noexcept
requires (iterable_expression<F>)

in1d

Returns a boolean array of the same shape as element that is true where an element of element is in test_elements and False otherwise.

Parameters:
  • element – an xexpression

  • test_elements – an array

Returns:

a boolean array

template<class E, std::forward_iterator I>
inline auto in1d(E &&element, I &&test_elements_begin, I &&test_elements_end) noexcept

in1d

Returns a boolean array of the same shape as element that is true where an element of element is in test_elements and False otherwise.

Parameters:
  • element – an xexpression

  • test_elements_begin – iterator to the beginning of an array

  • test_elements_end – iterator to the end of an array

Returns:

a boolean array

group Comparison operators

Functions

template<class E1, class E2>
inline auto operator<(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::less, E1, E2>

Lesser than.

Returns an xfunction for the element-wise lesser than comparison of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator<=(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::less_equal, E1, E2>

Lesser or equal.

Returns an xfunction for the element-wise lesser or equal comparison of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator>(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::greater, E1, E2>

Greater than.

Returns an xfunction for the element-wise greater than comparison of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator>=(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::greater_equal, E1, E2>

Greater or equal.

Returns an xfunction for the element-wise greater or equal comparison of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline std::enable_if_t<xoptional_comparable<E1, E2>::value, bool> operator==(const xexpression<E1> &e1, const xexpression<E2> &e2)

Equality.

Returns true if e1 and e2 have the same shape and hold the same values. Unlike other comparison operators, this does not return an xfunction.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

a boolean

template<class E1, class E2>
inline bool operator!=(const xexpression<E1> &e1, const xexpression<E2> &e2)

Inequality.

Returns true if e1 and e2 have different shapes or hold the different values. Unlike other comparison operators, this does not return an xfunction.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

a boolean

template<class E1, class E2>
inline auto equal(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::equal_to, E1, E2>

Element-wise equality.

Returns an xfunction for the element-wise equality of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto not_equal(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::not_equal_to, E1, E2>

Element-wise inequality.

Returns an xfunction for the element-wise inequality of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto less(E1 &&e1, E2 &&e2) noexcept -> decltype(std::forward<E1>(e1) < std::forward<E2>(e2))

Lesser than.

Returns an xfunction for the element-wise lesser than comparison of e1 and e2. This function is equivalent to operator<(E1&&, E2&&).

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto less_equal(E1 &&e1, E2 &&e2) noexcept -> decltype(std::forward<E1>(e1) <= std::forward<E2>(e2))

Lesser or equal.

Returns an xfunction for the element-wise lesser or equal comparison of e1 and e2. This function is equivalent to operator<=(E1&&, E2&&).

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto greater(E1 &&e1, E2 &&e2) noexcept -> decltype(std::forward<E1>(e1) > std::forward<E2>(e2))

Greater than.

Returns an xfunction for the element-wise greater than comparison of e1 and e2. This function is equivalent to operator>(E1&&, E2&&).

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto greater_equal(E1 &&e1, E2 &&e2) noexcept -> decltype(std::forward<E1>(e1) >= std::forward<E2>(e2))

Greater or equal.

Returns an xfunction for the element-wise greater or equal comparison of e1 and e2. This function is equivalent to operator>=(E1&&, E2&&).

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

group Bitwise operators

Functions

template<class E1, class E2>
inline auto operator&(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::bitwise_and, E1, E2>

Bitwise and.

Returns an xfunction for the element-wise bitwise and of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator|(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::bitwise_or, E1, E2>

Bitwise or.

Returns an xfunction for the element-wise bitwise or of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E1, class E2>
inline auto operator^(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::bitwise_xor, E1, E2>

Bitwise xor.

Returns an xfunction for the element-wise bitwise xor of e1 and e2.

Parameters:
  • e1 – an xexpression or a scalar

  • e2 – an xexpression or a scalar

Returns:

an xfunction

template<class E>
inline auto operator~(E &&e) noexcept -> detail::xfunction_type_t<detail::bitwise_not, E>

Bitwise not.

Returns an xfunction for the element-wise bitwise not of e.

Parameters:

e – an xexpression

Returns:

an xfunction

template<class E1, class E2>
inline auto left_shift(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::left_shift, E1, E2>

Bitwise left shift.

Returns an xfunction for the element-wise bitwise left shift of e1 by e2.

Parameters:
  • e1 – an xexpression

  • e2 – an xexpression

Returns:

an xfunction

template<class E1, class E2>
inline auto right_shift(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<detail::right_shift, E1, E2>

Bitwise left shift.

Returns an xfunction for the element-wise bitwise left shift of e1 by e2.

Parameters:
  • e1 – an xexpression

  • e2 – an xexpression

Returns:

an xfunction

template<class E1, class E2>
inline auto operator<<(E1 &&e1, E2 &&e2) noexcept -> detail::shift_return_type_t<detail::left_shift, E1, E2>

Bitwise left shift.

Returns an xfunction for the element-wise bitwise left shift of e1 by e2.

See also

left_shift

Parameters:
  • e1 – an xexpression

  • e2 – an xexpression

Returns:

an xfunction

template<class E1, class E2>
inline auto operator>>(E1 &&e1, E2 &&e2) -> detail::shift_return_type_t<detail::right_shift, E1, E2>

Bitwise right shift.

Returns an xfunction for the element-wise bitwise right shift of e1 by e2.

See also

right_shift

Parameters:
  • e1 – an xexpression

  • e2 – an xexpression

Returns:

an xfunction

group Casting operators

Functions

template<class R, class E>
inline auto cast(E &&e) noexcept -> detail::xfunction_type_t<typename detail::cast<R>::functor, E>

Element-wise static_cast.

Returns an xfunction for the element-wise static_cast of e to type R.

Parameters:

e – an xexpression or a scalar

Returns:

an xfunction

Previous Next

© Copyright 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht.

Built with Sphinx using a theme provided by Read the Docs.