 |
NumCpp
2.4.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
|
Go to the documentation of this file.
65 template<
typename dtype>
67 Axis inAxis =
Axis::NONE,
const std::string& inInterpMethod =
"linear")
71 if (inPercentile < 0.0 || inPercentile > 100.0)
76 if (inInterpMethod !=
"linear" &&
77 inInterpMethod !=
"lower" &&
78 inInterpMethod !=
"higher" &&
79 inInterpMethod !=
"nearest" &&
80 inInterpMethod !=
"midpoint")
82 std::string errStr =
"input interpolation method is not a vaid option.\n";
83 errStr +=
"\tValid options are 'linear', 'lower', 'higher', 'nearest', 'midpoint'.";
102 const auto i =
static_cast<int32>(
std::floor(
static_cast<double>(inArray.
size() - 1) * inPercentile / 100.0));
103 const auto indexLower =
static_cast<uint32>(clip<uint32>(i, 0, inArray.
size() - 2));
108 if (inInterpMethod ==
"linear")
110 const double percentI =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
111 const double fraction = (inPercentile / 100.0 - percentI) /
112 (
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1) - percentI);
114 const double returnValue = arrayCopy[indexLower] + (arrayCopy[indexLower + 1] - arrayCopy[indexLower]) * fraction;
119 if (inInterpMethod ==
"lower")
125 if (inInterpMethod ==
"higher")
131 if (inInterpMethod ==
"nearest")
133 const double percent = inPercentile / 100.0;
134 const double percent1 =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
135 const double percent2 =
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1);
136 const double diff1 = percent - percent1;
137 const double diff2 = percent2 - percent;
139 switch (argmin<double>({ diff1, diff2 }).item())
154 if (inInterpMethod ==
"midpoint")
156 NdArray<dtype> returnArray = {
static_cast<dtype
>((arrayCopy[indexLower] + arrayCopy[indexLower + 1]) / 2.0) };
168 for (
uint32 row = 0; row < inShape.
rows; ++row)
182 for (
uint32 row = 0; row < inShape.
rows; ++row)
value_type item() const
Definition: NdArrayCore.hpp:2975
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
std::int32_t int32
Definition: Types.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
NdArray< dtype > percentile(const NdArray< dtype > &inArray, double inPercentile, Axis inAxis=Axis::NONE, const std::string &inInterpMethod="linear")
Definition: percentile.hpp:66
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:52
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4652
std::uint32_t uint32
Definition: Types.hpp:40
dtype floor(dtype inValue) noexcept
Definition: floor.hpp:48
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
iterator end() noexcept
Definition: NdArrayCore.hpp:1431
size_type size() const noexcept
Definition: NdArrayCore.hpp:4370
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1487
Axis
Enum To describe an axis.
Definition: Types.hpp:46
Definition: Coordinate.hpp:44
uint32 rows
Definition: Core/Shape.hpp:44
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1143
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:629
iterator begin() noexcept
Definition: NdArrayCore.hpp:1087