NumCpp  2.11.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
var.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include <algorithm>
31 #include <complex>
32 
35 #include "NumCpp/NdArray.hpp"
36 
37 namespace nc
38 {
39  //============================================================================
40  // Method Description:
50  template<typename dtype>
51  NdArray<double> var(const NdArray<dtype>& inArray, Axis inAxis = Axis::NONE)
52  {
54 
55  NdArray<double> stdValues = stdev(inArray, inAxis);
56  const auto function = [](double& value) -> void { value *= value; };
57 
58  stl_algorithms::for_each(stdValues.begin(), stdValues.end(), function);
59  return stdValues;
60  }
61 
62  //============================================================================
63  // Method Description:
73  template<typename dtype>
74  NdArray<std::complex<double>> var(const NdArray<std::complex<dtype>>& inArray, Axis inAxis = Axis::NONE)
75  {
77 
78  NdArray<std::complex<double>> stdValues = stdev(inArray, inAxis);
79  const auto function = [](std::complex<double>& value) -> void { value *= value; };
80 
81  stl_algorithms::for_each(stdValues.begin(), stdValues.end(), function);
82  return stdValues;
83  }
84 } // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
iterator end() noexcept
Definition: NdArrayCore.hpp:1576
iterator begin() noexcept
Definition: NdArrayCore.hpp:1268
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:225
Definition: Cartesian.hpp:40
Axis
Enum To describe an axis.
Definition: Types.hpp:47
NdArray< double > stdev(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: stdev.hpp:52
NdArray< double > var(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: var.hpp:51