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