NumCpp  2.1.0
A C++ implementation of the Python Numpy library
var.hpp
Go to the documentation of this file.
1 #pragma once
30 
33 #include "NumCpp/NdArray.hpp"
34 
35 #include <algorithm>
36 #include <complex>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
52  template<typename dtype>
53  NdArray<double> var(const NdArray<dtype>& inArray, Axis inAxis = Axis::NONE)
54  {
56 
57  NdArray<double> stdValues = stdev(inArray, inAxis);
58  const auto function = [](double& value) -> void
59  {
60  value *= value;
61  };
62 
63  stl_algorithms::for_each(stdValues.begin(), stdValues.end(), function);
64  return stdValues;
65  }
66 
67  //============================================================================
68  // Method Description:
79  template<typename dtype>
80  NdArray<std::complex<double>> var(const NdArray<std::complex<dtype>>& inArray, Axis inAxis = Axis::NONE)
81  {
83 
84  NdArray<std::complex<double>> stdValues = stdev(inArray, inAxis);
85  const auto function = [](std::complex<double>& value) -> void
86  {
87  value *= value;
88  };
89 
90  stl_algorithms::for_each(stdValues.begin(), stdValues.end(), function);
91  return stdValues;
92  }
93 } // namespace nc
StaticAsserts.hpp
nc::Axis::NONE
@ NONE
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::NdArray< double >
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:214
NdArray.hpp
nc::NdArray::end
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
stdev.hpp
nc::Axis
Axis
Enum To describe an axis.
Definition: Types.hpp:47
nc::stdev
NdArray< double > stdev(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: stdev.hpp:54
nc
Definition: Coordinate.hpp:45
nc::var
NdArray< double > var(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition: var.hpp:53
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091