NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
digitize.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <algorithm>
31#include <cstdint>
32#include <iterator>
33
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
50 template<typename dtype1, typename dtype2>
52 {
53 const auto uniqueBins = unique(bins);
54 auto result = NdArray<uint32>(1, x.size());
55 result.fill(0);
56
57 typename decltype(result)::size_type idx{ 0 };
59 x.end(),
60 [&uniqueBins, &result, &idx](const auto value)
61 {
62 const auto upperBin = std::upper_bound(uniqueBins.begin(), uniqueBins.end(), value);
63 result[idx++] = static_cast<uint32>(std::distance(uniqueBins.begin(), upperBin));
64 });
65
66 return result;
67 }
68} // namespace nc
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
size_type size() const noexcept
Definition: NdArrayCore.hpp:4524
iterator end() noexcept
Definition: NdArrayCore.hpp:1623
iterator begin() noexcept
Definition: NdArrayCore.hpp:1315
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:225
Definition: Cartesian.hpp:40
NdArray< uint32 > digitize(const NdArray< dtype1 > &x, const NdArray< dtype2 > &bins)
Definition: digitize.hpp:51
NdArray< dtype > unique(const NdArray< dtype > &inArray)
Definition: unique.hpp:53