NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nanpercentile.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <cmath>
32#include <string>
33#include <vector>
34
35#include "NumCpp/Core/Enums.hpp"
39#include "NumCpp/Core/Shape.hpp"
40#include "NumCpp/Core/Types.hpp"
45#include "NumCpp/NdArray.hpp"
47
48namespace nc
49{
50 //============================================================================
51 // Method Description:
62 template<typename dtype>
64 double inPercentile,
67 {
69
70 switch (inAxis)
71 {
72 case Axis::NONE:
73 {
74 std::vector<double> arrayCopy;
75 arrayCopy.reserve(inArray.size());
76 for (auto value : inArray)
77 {
78 if (!isnan(value))
79 {
80 arrayCopy.push_back(static_cast<double>(value));
81 }
82 }
83
84 if (arrayCopy.empty())
85 {
87 return returnArray;
88 }
89
91 static_cast<typename NdArray<dtype>::size_type>(arrayCopy.size()),
96 }
97 case Axis::COL:
98 {
99 const Shape inShape = inArray.shape();
100
102 for (uint32 row = 0; row < inShape.rows; ++row)
103 {
108
109 if (outValue.isscalar())
110 {
111 returnArray[row] = outValue.item();
112 }
113 else
114 {
116 }
117 }
118
119 return returnArray;
120 }
121 case Axis::ROW:
122 {
124 }
125 default:
126 {
127 THROW_INVALID_ARGUMENT_ERROR("Unimplemented axis type.");
128 return {}; // get rid of compiler warning
129 }
130 }
131
132 return {}; // get rid of compiler warning
133 }
134} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
#define STATIC_ASSERT_FLOAT(dtype)
Definition StaticAsserts.hpp:50
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
uint32 size_type
Definition NdArrayCore.hpp:156
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
const double nan
NaN.
Definition Core/Constants.hpp:41
Definition Cartesian.hpp:40
NdArray< double > nanpercentile(const NdArray< dtype > &inArray, double inPercentile, Axis inAxis=Axis::NONE, InterpolationMethod inInterpMethod=InterpolationMethod::LINEAR)
Definition nanpercentile.hpp:63
InterpolationMethod
Definition Enums.hpp:139
Axis
Enum To describe an axis.
Definition Enums.hpp:36
NdArray< double > percentile(const NdArray< dtype > &inArray, double inPercentile, Axis inAxis=Axis::NONE, InterpolationMethod inInterpMethod=InterpolationMethod::LINEAR)
Definition percentile.hpp:66
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
bool isnan(dtype inValue) noexcept
Definition isnan.hpp:49
std::uint32_t uint32
Definition Types.hpp:40