 |
NumCpp
2.1.0
A C++ implementation of the Python Numpy library
|
Go to the documentation of this file.
66 template<
typename dtype>
68 Axis inAxis =
Axis::NONE,
const std::string& inInterpMethod =
"linear")
72 if (inPercentile < 0.0 || inPercentile > 100.0)
77 if (inInterpMethod !=
"linear" &&
78 inInterpMethod !=
"lower" &&
79 inInterpMethod !=
"higher" &&
80 inInterpMethod !=
"nearest" &&
81 inInterpMethod !=
"midpoint")
83 std::string errStr =
"input interpolation method is not a vaid option.\n";
84 errStr +=
"\tValid options are 'linear', 'lower', 'higher', 'nearest', 'midpoint'.";
103 const auto i =
static_cast<int32>(
std::floor(
static_cast<double>(inArray.
size() - 1) * inPercentile / 100.0));
104 const auto indexLower =
static_cast<uint32>(clip<uint32>(i, 0, inArray.
size() - 2));
109 if (inInterpMethod ==
"linear")
111 const double percentI =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
112 const double fraction = (inPercentile / 100.0 - percentI) /
113 (
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1) - percentI);
115 const double returnValue = arrayCopy[indexLower] + (arrayCopy[indexLower + 1] - arrayCopy[indexLower]) * fraction;
120 if (inInterpMethod ==
"lower")
126 if (inInterpMethod ==
"higher")
132 if (inInterpMethod ==
"nearest")
134 const double percent = inPercentile / 100.0;
135 const double percent1 =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
136 const double percent2 =
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1);
137 const double diff1 = percent - percent1;
138 const double diff2 = percent2 - percent;
140 switch (argmin<double>({ diff1, diff2 }).item())
155 if (inInterpMethod ==
"midpoint")
157 NdArray<dtype> returnArray = {
static_cast<dtype
>((arrayCopy[indexLower] + arrayCopy[indexLower + 1]) / 2.0) };
169 for (
uint32 row = 0; row < inShape.
rows; ++row)
183 for (
uint32 row = 0; row < inShape.
rows; ++row)
value_type item() const
Definition: NdArrayCore.hpp:2958
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
std::int32_t int32
Definition: Types.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
NdArray< dtype > percentile(const NdArray< dtype > &inArray, double inPercentile, Axis inAxis=Axis::NONE, const std::string &inInterpMethod="linear")
Definition: percentile.hpp:67
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:53
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4608
std::uint32_t uint32
Definition: Types.hpp:41
dtype floor(dtype inValue) noexcept
Definition: floor.hpp:49
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
size_type size() const noexcept
Definition: NdArrayCore.hpp:4326
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
Axis
Enum To describe an axis.
Definition: Types.hpp:47
Definition: Coordinate.hpp:45
uint32 rows
Definition: Core/Shape.hpp:45
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:630
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091